I'm going through the series 16f to 18f series (exactly the 18f2620)
configure it already was an odyssey.
Now I'm planning for the first time and I can not get out.
I think you can't access register bits directly (in pic14 port it's possible). Replace WREN with EECON1bits.WREN, RD3 with LATDbits.LATD3, etc.
It's better to include pic18fregs.h than pic18f2620.h. The compiler knows which model you're using and will select the correct header (code becomes more portable)
The way of defining fuses, changed. See the link with the examples or look for Configuration Bits on the pic16 section of SDCC manual.
Regards,
Diego
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm going through the series 16f to 18f series (exactly the 18f2620)
configure it already was an odyssey.
Now I'm planning for the first time and I can not get out.
include <pic18f2620.h>
define KHZ 20000
code char at 0x300001 CONFIG1H = 0x0C; //IESO=0, FCMEN=0, HS OSCILADOR
code char at 0x300002 CONFIG2L = 0x1F; //BORV1=1,BORV0=1,BORN1=1,BORN0=1,PWERTEN=0
code char at 0x300003 CONFIG2H = 0x00; //WDTPS3:WDTPS0=0(Postscale 1:1),WDTEN=0
code char at 0x300005 CONFIG3H = 0x01; //MCLRE=0,LPT1OSC=0,PBADEN=0,CCP2MX=PORTC.1
code char at 0x300006 CONFIG4L = 0x85; //DEBUG=1,XINST=0,LVP=0,STVREN=1
code char at 0x300008 CONFIG5L = 0x0F; //CP3=1,CP2=1,CP1=1,CP0=1
code char at 0x300009 CONFIG5H = 0xC0; //CPD=1,CPB=1
code char at 0x30000A CONFIG6L = 0x0F; //WRT3=1,WRT2=1,WRT1=1,WRT0=1
code char at 0x30000B CONFIG6H = 0xE0; //WRTD=1,WRTB=1,WRTC=1
code char at 0x30000C CONFIG7L = 0x0F; //EBTR3=1,EBTR2=1,EBTR1=1,EBTR0=1
code char at 0x30000D CONFIG7H = 0x40; //EBTRB=1
void Delay_us(unsigned char Tiempo_us)
{
Tiempo_us;
asm
sublw 1
ciclo_us:
ADDLW 1
btfss 0x03,0
goto ciclo_us
endasm;
}
void Delay_ms(unsigned int Tiempo_ms)
{
unsigned int Contador_ms;
for(Contador_ms=0;Contador_ms<(Tiempo_ms/3);Contador_ms++)
{
Delay_us(1000);
}
}
void Init_config()
{
TRISA=0b000000;
TRISB=0b00000000;
TRISC=0b00011000;
TRISE=0;
PORTA=0b000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTE=0;
INTCON=0b00000000;
CCP1CON=0b00000000;
CCP2CON=0b00000000;
ADCON0=0b00000000;
ADCON1=0b00000110;
}
void Wr_Eeprom(unsigned long Address,unsigned char Dato)
{
EEADRH=(Address>>8);
EEADR=Address;
EEDATA=Dato;
EPGD=0;
CFGS=0;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
while(EEIF==0);
EEIF=0;
WREN=0;
}
unsigned char Rd_Eeprom(unsigned int Address)
{
EEADR=Address;
EEPGD=0;
RD=1;
return EEDATA;
}
void main(void)
{
unsigned int Contador;
Init_config();
Delay_ms(500);
for(Contador=0;Contador<254;Contador++)
{
Wr_Eeprom(Contador,Contador);
RD3=1;
Delay_ms(25);
RD3=0;
Delay_ms(25);
}
while(1);
}
18F2620_Drone.c|59|error 20: Undefined identifier 'EPGD'|
18F2620_Drone.c|60|error 20: Undefined identifier 'CFGS'|
18F2620_Drone.c|61|error 20: Undefined identifier 'WREN'|
18F2620_Drone.c|64|error 20: Undefined identifier 'WR'|
18F2620_Drone.c|65|error 20: Undefined identifier 'EEIF'|
18F2620_Drone.c|66|error 20: Undefined identifier 'EEIF'|
18F2620_Drone.c|67|error 20: Undefined identifier 'WREN'|
18F2620_Drone.c|73|error 20: Undefined identifier 'EEPGD'|
18F2620_Drone.c|74|error 20: Undefined identifier 'RD'|
18F2620_Drone.c|86|error 20: Undefined identifier 'RD3'|
18F2620_Drone.c|88|error 20: Undefined identifier 'RD3'|
||=== Build finished: 11 errors, 0 warnings ===|
Which compile command are you executing?
Here you can find up-to-date examples for pic14 (16F) and pic16 (18f). Maybe they're useful to you.
https://github.com/diegoherranz/sdcc-examples
Just a fast comments:
I think you can't access register bits directly (in pic14 port it's possible). Replace WREN with EECON1bits.WREN, RD3 with LATDbits.LATD3, etc.
It's better to include pic18fregs.h than pic18f2620.h. The compiler knows which model you're using and will select the correct header (code becomes more portable)
The way of defining fuses, changed. See the link with the examples or look for Configuration Bits on the pic16 section of SDCC manual.
Regards,
Diego
Thanks Diego.
I almost solved.
Only by an error on these lines:
void Wr_Eeprom(unsigned long Address,unsigned char Dato)
{
EEADRH=(Address>>8);
EEADR=Address;
EEDATA=Dato;
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.WREN=1;
EECON2=0x55;
EECON2=0xAA;
EECON1bits.WR=1;
while(PIR2.EEIF==0); //Aqui
PIR2.EEIF=0; //Aqui
EECON1bits.WREN=0;
}
and from this error in the board
void Wr_Eeprom(unsigned long Address,unsigned char Dato)
18F2620_Drone.c|66|error 25: Structure/Union expected left of '.->'|
18F2620_Drone.c|67|error 25: Structure/Union expected left of '.->'|
||=== Build finished: 2 errors, 0 warnings ===|
forget it ...
void Wr_Eeprom(unsigned long Address,unsigned char Dato)
{
EEADRH=(Address>>8);
EEADR=Address;
EEDATA=Dato;
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.WREN=1;
EECON2=0x55;
EECON2=0xAA;
EECON1bits.WR=1;
while(PIR2bits.EEIF==0); //Aqui
PIR2bits.EEIF=0; //Aqui
EECON1bits.WREN=0;
}
thanks again, switching to 18f will have on problemmi
Last edit: alejandro1957 2015-01-16