chipKIT® Development Platform

Inspired by Arduino™

Help on porting code-register set

Created Tue, 23 Aug 2016 20:52:30 +0000 by Ivan.pepe80


Ivan.pepe80

Tue, 23 Aug 2016 20:52:30 +0000

Hello.I am Ivan.I am interested to port my code from atmega328(arduino)to a pic32mx270f256d.I don't know how to port this part of code:

//Port Manipulation
#define CS_on PORTC |= 0x08   //00001000 //Pin PC3 High//A3
#define CS_off PORTC &= 0xF7  //11110111 //Pin PC3 Low //A3
#define SCK_on PORTC |= 0x04  //00000100 //Pin PC2 High//A2
#define SCK_off PORTC &= 0xFB //11111011 //Pin PC2 Low //A2
#define SDI_on PORTC |= 0x02  //00000010 //Pin PC1 High//A1
#define SDI_off PORTC &= 0xFD //11111101 //Pin PC1 Low //A1
#define GIO_on PORTC |=0x01   //00000001 //Pin PC0 High//A0

//Input e output setup
#define SDI_1 (PINC & 0x02) == 0x02 //00000010 //Pin PC1 input
#define SDI_0 (PINC & 0x02) == 0x00 //00000000 //Pin PC1 output
#define GIO_1 (PINC & 0x01) == 0x01 //00000001 //Pin PC0 input 
#define GIO_0 (PINC & 0x01) == 0x00 //00000000 //Pin PC0 output

#define RED_LED_pin 13 //PB5 Pin //output
#define Red_LED_ON PORTB |= _BV(5);   //byte value 5 //Pin high
#define Red_LED_OFF PORTB &= ~_BV(5); //Pin Low

Thanks for your help!


majenko

Tue, 23 Aug 2016 21:22:19 +0000

Simplest is to replace them with standard digitalRead() and digitalWrite().

//Port Manipulation
#define CS_on digitalWrite(10, HIGH);
#define CS_off digitalWrite(10, LOW);
... etc ...

//Input e output setup
#define SDI_1 digitalRead(3) == HIGH
#define SDI_0 digitalRead(3) == LOW
... etc ...

Ivan.pepe80

Wed, 24 Aug 2016 07:31:42 +0000

Thanks for your help! :D Ivan Pepe