I am using the Silabs IDE with the SDCC compiler under windows 7 for the Silabs C8051F340 embedded processor. I am Using the Silabs C8051F34x-DK development board for testing.
SDCC version is 3.5.0
I am compiling using: SDCC -c --debug --use-stdout -V -I"C:\program files\SDCC\include\mcs51" –model-large
I include the “c8051f340.h” file in my main from the SDCC includes.
My program appears to hang in the start-up routines, looping around 5B to 5C and 7C to 7E. I think it is trying to clear memory. I need to use registers P2.0, P2.2, P2.6 and P2.7 for I/O.
_XPAGE is defined in “c8051f340.h” – I don't know what to do with it.
I need the large model to hold the data I intend to take in – it won't fit in the small model.
Attaching: target_main.c, target_main.h, target.wsp, etc.
BTW, the blinky program compiles and executes fine after a few changes to the code inserting underscores such as __SFR …. worked in large memory model.
//===========================================================================// Target Controller Program//// copyright Wojcik Technical Services 11/07/2015//===========================================================================//===========================================================================// Includes //===========================================================================#include<C:\program files\sdcc\include\mcs51\c8051f340.h> // SFR declarations#include<target_main.h>#include<stdio.h>//===========================================================================// Function Prototypes //===========================================================================charCompare_characters(char*string1,char*string2,unsignedcharn);chargetchar(void);char_getkey(void);voidInitialize(void);voidInterrupts_Init(void);voidPort_IO_Init(void);voidputchar(charc);voidTransmit_character(void);voidTimer_Init(void);voidUART_Init(void);voidSerial_interrupt(void)__interrupt4;//===========================================================================// Global Variables//===========================================================================//-------------- String Variables ---------------------__codecharuart_init[]={"UART Initialized\r\n"};__codecharhello[]={"\n\rTarget Contoller Initialized\n\r"};__codecharfaced[]={"Faced\r\n"};__codecharedged[]={"Edged\r\n"};//-------------- Serial Com Variables -----------------__xdataunsignedchartbuf[TBUFSIZE+1],rbuf[RBUFSIZE+1];signedinttbuf_head,tbuf_tail,rbuf_head,rbuf_tail,tbuf_count,rbuf_count;charcmd_buf[15],cmd_counter,in_char;chartbuf_flag;//-------------- Misc Variables -----------------------unsignedcharbutton_status;unsignedinti,j;//===========================================================================voidmain(void){LED=ON;//??Initialize();TARGET=FACE;LIGHT=!TARGET;LED=OFF;LED=ON;//??while(FOREVER){if(rbuf_count>0){// process incoming from the serial port in_char=_getkey();if(in_char=='\r'){while(rbuf_count>0)_getkey();// if a cr, clear buffercmd_counter=0;}else{cmd_buf[cmd_counter++]=in_char;if(cmd_counter>=4)// process the command{cmd_buf[4]='\0';if(Compare_characters(cmd_buf,faced,4)){TARGET=FACE;LIGHT=!TARGET;printf(faced);LED=OFF;LED=ON;//??while(tbuf_count>0)Transmit_character();}if(Compare_characters(cmd_buf,edged,4)){TARGET=EDGE;LIGHT=!TARGET;printf(edged);LED=ON;while(tbuf_count>0)Transmit_character();}for(cmd_counter=0;cmd_counter<15;cmd_counter++)// clean upcmd_buf[cmd_counter]=0;}// end process the comand}// end else}// end rbuf_count >0if(button_status!=BUTTON){button_status=BUTTON;if(button_status==0){printf("pressed\r\n");while(tbuf_count>0)Transmit_character();}else{printf("released\r\n");while(tbuf_count>0)Transmit_character();}for(i=0;i<40000;i++)// waste some time for switch bouncej=i;}}// End of FOREVER, but of course FOREVER never ends}// end of main//===========================================================================voidInitialize(void){EA=OFF;// All interrupts offPCA0MD=0x00;// WDTE = 0 (clear watchdog timer enable)OSCICN=SIX_MHZ;// Enable oscillator at 6 mhz (0x82)Port_IO_Init();TARGET=FACE;LIGHT=OFF;LED=ON;tbuf_head=tbuf_tail=rbuf_head=rbuf_tail=0;tbuf_count=rbuf_count=0;cmd_counter=0;Timer_Init();UART_Init();Interrupts_Init();button_status=ON;printf(hello);while(tbuf_count>0)Transmit_character();}//===========================================================================voidPort_IO_Init(){P2MDIN=0x01;// P2.0 open collector, weak pull up, non analogP2MDOUT=0x44;// P2.2 & P2.6 push/pull digitalP2SKIP=0x44;// Skip P2.2 & P2.6 (LED & relay outputsXBR0=0x01;// UART 0 enabledXBR1=0x40;// weak pull-up enabled, crossbar enabled}//===========================================================================voidTimer_Init()// Timer 1 used by UART0 set for 9600 baud{TCON=0x40;// Timer 1 offTMOD=0x20;// Timer 1 8 bit, auto reloadCKCON=0x01;// Timer 1 clock is SYSCLK (6 mhz)TH1=0xB2;// Timer 1 reload value 9600 baudTCON=0x40;// Turn on timer 1 level triggered}//===========================================================================voidUART_Init(){SCON0=0x10;// enable receptiontbuf_flag=TRUE;printf(uart_init);}//===========================================================================voidInterrupts_Init(){IE=0x90;// enable (EA) + UART0}//===========================================================================voidSerial_interrupt(void)__interrupt4// Uses timer1{EA=0;// Disable all interruptsif(RI0){// If a read, put char in circular bufferrbuf[rbuf_tail++]=SBUF0;if(rbuf_tail>(RBUFSIZE-1))rbuf_tail-=RBUFSIZE;if((rbuf_count=(rbuf_tail-rbuf_head))<0)rbuf_count+=RBUFSIZE;RI0=FALSE;// Clear read interrupt flag}if(TI0){tbuf_flag=TRUE;// If a write finished, set a flagTI0=FALSE;// Clear write interrupt flag}EA=1;// enable all interrupts}//===========================================================================chargetchar(void){charr;r=_getkey();// Call _getkey to get a char from bufferputchar(r);// Echo the character// if(r == '\r') // Convert returns to endline// r = '\n';returnr;// Return the character}//===========================================================================char_getkey()// returns a character from the circular buffer, or NULL{charc;if(rbuf_count>0){c=rbuf[rbuf_head++];if(rbuf_head>RBUFSIZE_MINUS)rbuf_head-=RBUFSIZE;if((rbuf_count=(rbuf_tail-rbuf_head))<0)rbuf_count+=RBUFSIZE;return(c);}elsereturn(char)0;}//===========================================================================voidputchar(charc)// Puts characters into a circular buffer{// Counts characters, buffer can overwitetbuf[tbuf_tail++]=c;if(tbuf_tail>TBUFSIZE_MINUS)tbuf_tail-=TBUFSIZE;if((tbuf_count=tbuf_tail-tbuf_head)<0)tbuf_count+=TBUFSIZE;}//===========================================================================voidTransmit_character(void)// Unpacks characters from a circular buffer{// and tansmits themif(tbuf_flag){// tbuf_flag will be TRUE when xmitter availableSBUF0=tbuf[tbuf_head++];if(tbuf_head>(TBUFSIZE-1))tbuf_head-=TBUFSIZE;tbuf_flag=FALSE;if((tbuf_count=tbuf_tail-tbuf_head)<0)tbuf_count+=TBUFSIZE;}}//===========================================================================charCompare_characters(char*string1,char*string2,unsignedcharn){unsignedcharcount,equal_flag;equal_flag=0;for(count=0;count<n;count++){if(string1[count]==string2[count]){equal_flag=TRUE;}else{equal_flag=FALSE;returnequal_flag;}}returnequal_flag;}//===========================================================================// END OF FILE//===========================================================================//-------------------------------------------------------------------------// Oscillator definitions//-------------------------------------------------------------------------#define ONE_MHZ 0x00 // 1.5 mhz#define THREE_MHZ 0x81 // 3 mhz#define SIX_MHZ 0x82 // 6 mhz#define TWELVE_MHZ 0x83 // 12 mhz//-------------------------------------------------------------------------// Serial port definitions//-------------------------------------------------------------------------#define TBUFSIZE 128#define TBUFSIZE_MINUS TBUFSIZE - 1#define RBUFSIZE 128#define RBUFSIZE_MINUS RBUFSIZE - 1//-------------------------------------------------------------------------// Hardware definitions//-------------------------------------------------------------------------__sbit__at(0xA6)TARGET;// target relay control port (2.6)__sbit__at(0xA7)LIGHT;// target relay control = !target port (2.7)__sbit__at(0xA2)LED;// LED port (2.2)__sbit__at(0xA0)BUTTON;// push button sense (2.0)//-------------------------------------------------------------------------// Miscelaneous definitions//-------------------------------------------------------------------------#define ONE 1#define ZERO 0#define ON 1#define OFF 0#define FOREVER 1#define LOW 0#define HIGH 1#define TRUE 1#define FALSE 0#define FACE 0#define EDGE 1//-------------------------------------------------------------------------// End of File//-------------------------------------------------------------------------
Thanks,
Leonard Wojcik
801-272-1813
leonard@wojciktech.com
Last edit: Maarten Brock 2015-12-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the Silabs IDE with the SDCC compiler under windows 7 for the Silabs C8051F340 embedded processor. I am Using the Silabs C8051F34x-DK development board for testing.
SDCC version is 3.5.0
I am compiling using: SDCC -c --debug --use-stdout -V -I"C:\program files\SDCC\include\mcs51" –model-large
I include the “c8051f340.h” file in my main from the SDCC includes.
Assembly with: sdas8051 -plosgff;
Linking with: sdcc --debug --use-stdout -V –model-large.
My program appears to hang in the start-up routines, looping around 5B to 5C and 7C to 7E. I think it is trying to clear memory. I need to use registers P2.0, P2.2, P2.6 and P2.7 for I/O.
_XPAGE is defined in “c8051f340.h” – I don't know what to do with it.
I need the large model to hold the data I intend to take in – it won't fit in the small model.
Attaching: target_main.c, target_main.h, target.wsp, etc.
BTW, the blinky program compiles and executes fine after a few changes to the code inserting underscores such as __SFR …. worked in large memory model.
Thanks,
Leonard Wojcik
801-272-1813
leonard@wojciktech.com
Last edit: Maarten Brock 2015-12-05
Hi Leonard,
your problem is most likely a watchdog problem, see Program never gets to the main() function