Hello,

I have recently moved to SDCC and even more recently started using PIC18*,
more specifically 18f2550. I have two problems that I canät seem to figure
out;

1. Whenever power is applied, the device seems to start up in a random
state and doesn't seem to start running the program. Programming the
device seems so make the device do *something*, but that seems quite
random as well, at different times, flashing the device with the exacttly
same hef file seems to do different things each time.
I program the device while it is in the circuit, the ICSP lines are
dedicated to programming, and a standard ASCII LCD is attatched in 4-bit
mode.

I build the hex file using this Makefile:
CC=/usr/local/bin/sdcc
CFLAGS= -mpic16 -p18f2550 --pstack-model=large

all: main.hex

main.dos.hex: main.hex

         #-unix2dos   -n main.hex  main.hex.dos

main.hex:  main.c lcd.o
         $(CC) $(CFLAGS) main.c lcd.o


lcd.o: lcd.c
         $(CC) $(CFLAGS) -c lcd.c

clean:
         -rm *.asm *.cod *.hex  *.lst *.o


The relevant parts of the main.c is

#include <pic18fregs.h>
#include <delay.h>
#include "lcd.h"
#include "main.h"
typedef unsigned int config;
code char at __CONFIG1L _config0 = 0x20; //0b00100000
code char at __CONFIG1H _config1 = 0x08; //0b00001000
code char at __CONFIG2L _config2 = 0x18; //0b00011000
code char at __CONFIG2H _config3 = 0x00; //0b00000000

code char at __CONFIG3H _config4 = 0x00; //0b00000000
code char at __CONFIG4L _config5 = 0xc0; //0b11000000

code char at __CONFIG5L _config6 = 0x0f; //0b00001111
code char at __CONFIG5H _config7 = 0xc0; //0b11000000
code char at __CONFIG6L _config8 = 0x0f; //0b00001111
code char at __CONFIG6H _config9 = 0xe0; //b11100000
code char at __CONFIG7L _config10 = 0x0f; //0b00001111
code char at __CONFIG7H _config11 = 0x40; //0b01000000


void init(void)
{
         CVRCON=0x00;    //0b00000000
         OSCCON=0xf7;    //0b11110111
         CCP1CON=0x00;   //0b00000000
         CCP2CON=0x00;   //0b00000000
         UCFG=0x00;      //0b00000000
         ADCON0=0x00;    //0b00000000
         ADCON1=0x0f;    //0b00001111
         CMCON=0x07;     //0b00000000
         TRISA=0x00;     //0b00000000
         TRISB=0xff;     //0b11111111
         TRISC=0xfe;     //0b11111110
}

// Snipped the "boring" parts

void main(void)
{
   init();
   delay100ktcy(9);
   LCDinit();
   delay100ktcy(9);
   LCDconfig();
   while(1)
   {
     LCDputc(0x41);        //This is just an example of a function in lcd.c
   }
}




and then in lcd.c, the relevant function would be:

void LCDputc(unsigned char c)
{
   RS=1;
   RW=0;
   EN=1;
   delay1ktcy(9);
   LATAbits.LATA0=(c>>7)&0x01;
   LATAbits.LATA1=(c>>6)&0x01;
   LATAbits.LATA2=(c>>5)&0x01;
   LATAbits.LATA3=(c>>4)&0x01;
   delay1ktcy(9);
   EN=0;
   delay1ktcy(9);
   EN=1;
   delay1ktcy(9);
   LATAbits.LATA0=(c>>3)&0x01;
   LATAbits.LATA1=(c>>2)&0x01;
   LATAbits.LATA2=(c>>1)&0x01;
   LATAbits.LATA3=c&0x01;
   delay1ktcy(9);
   EN=0;
   delay1ktcy(9);
   LATA=PORTA&0xf0;
}


...which brings me to problem nr...

2. When I call LCDputc(somechar);, the "somechar" never seems to reach the
function, the unsigned char c won't be what it is supposed to be.
Apparently I have missed something here... I have spent a lot of time
trying to figure this out, but I have been totally stuck...

SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.2
#4886 (Jul 23 2007) (UNIX), running on amd64/linux.

Thank you,

Robert Bergfors



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to