??? 11/28/08 20:23 Read: times |
#160385 - Program hangs at one point - 8051F340 |
I am using SILABS IDE /keil with 8051F340 chip. Sometimes, when the number of declarations increase, the program starts hanging immediately after main. When this happens, I start removing variables and code that uses more memory one by one and then at some point it starts working. I am sure I am making a fundamental mistake here. For example, in the code posted, the program counter reaches the first line after while(1) and then it loops some where else. ie: It doesn't reach the next line if I single step or insert a break point. If I remove TI0=1; then the PC goes one step extra and then hangs. If I remove 2 lines ie: EA = 1; I0=1; then it goes an extra step ie: till next while statement. Full code is attached. I am using 256 as RAM size in linker options for keil linker. (When I select 4096, I get error while linking saying that the RAM size has been exceded - even though I have 4096 RAM. But then I am able to use xdata to make use of my RAM). Please have a look at the code and guide..
void main (void) { u_char sel = 0; u_char stage =1; u_char bmodify=0; PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer enable) PORT_Init(); // Initialize Port I/O SYSCLK_Init(); // Initialize Oscillator UART0_Init(); Timer1_Init(); EA = 1; TI0=1; while(1) { if( stage == 1) //stage is actually 1 here. Program counter reaches till herethen loops some where else { stage = 0; //If I set a breakpoint here, PC doesn't reach here while(sel != 'e'&& sel != 'E') ...insert code here #pragma LARGE #include<c8051f340.h> #include<string.h> #include<stdio.h> //#include"manageserver.h" #define SYSCLK 12000000 // SYSCLK frequency in Hz #define BAUDRATE 9600 // Baud rate of UART in bps #define _ENDIAN_LITTLE_ 0 // This must be defined if system is little-endian alignment #define _ENDIAN_BIG_ 1 #define SYSTEM_ENDIAN _ENDIAN_BIG_ typedef unsigned char u_char; typedef unsigned int u_int; typedef unsigned long u_long; #define DEFAULT_NET_SIP 0xC0A818B3 //Default Source IP : 192.168.24.180 #define DEFAULT_NET_GWIP 0xC0A818B3 // Default Gateway IP : 192.168.24.180 #define DEFAULT_NET_SN 0xFFFFFF00 #define DEFAULT_LOCAL_PORT 3000 #define DEFAULT_BAUD 9600 #define DEFAULT_MODE '0' #define DEFAULT_DATA_PARM '1' #define DEFAULT_TIMEOUT '0' #define DEFAULT_RIP 0xc0a818b7 #define DEFAULT_IPFILTERING 0x00000000 #define DEFAULT_RPORT 3000 #define DEFAULT_SMODE '2' #define DEFAULT_DISCNCT '0' void SYSCLK_Init(void); void UART0_Init(void); void PORT_Init(void); void Timer1_Init(void); /*unsigned long htonl(unsigned long hostlong); char* inet_ntoa(unsigned long addr); char C2D(u_char c); u_int ATOI(char* str,u_int base); unsigned long inet_addr(unsigned char* addr); char* ITOA(u_int addrs); */ u_long swapl(u_long l); void set_serialconf(void); void set_server_confg(void); void Data_parameters(void); static u_char Server_config(void); static u_char manage_serial(void); unsigned char TX_Ready; unsigned char Byte=0,addr1_str[15]; unsigned int num; static u_char manage_network(void); typedef struct _NETCONF { u_int test; u_char mac[6]; u_long sip; u_long gwip; u_long sn; u_int l_port; u_char mode; }NETCONF; NETCONF NetConf; NETCONF* pNetConf; typedef struct _SERIALCONF { u_int baud; u_char dataparameter; u_char conn_timeout; }SERIALCONF; SERIALCONF Serial_conf; typedef struct _SERVERCONF { u_long rip; u_long ip_fltng; u_int r_port; u_char startmode; //u_char ACCP_conn; u_char DISS_conn; }SERVERCONF; SERVERCONF Server_Conf; void get_net_conf(void); u_char ipstr[15]; u_char smode,discnct,rtns; u_char select=0; u_int tnums; void print_server(u_char bits); //--------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- void main (void) { u_char sel = 0; u_char stage =1; u_char bmodify=0; PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer enable) PORT_Init(); // Initialize Port I/O SYSCLK_Init(); // Initialize Oscillator UART0_Init(); Timer1_Init(); EA = 1; TI0=1; while(1) { if( stage == 1) //stage is actually 1 here. Program counter reaches till here and then loops some where else { stage = 0; //If I set a breakpoint here, PC doesn't reach here while(sel != 'e'&& sel != 'E') { printf( "rn===================" "rnEVB B/D MANAGE MODE" "rn===================" "rn1 : Network Config" "rn2 : Serial Config" "rn3 : Server Config" "rnF : Factory Reset" "rnE : Exit" "rn===================" "rnSelect = "); scanf("%c",&sel); switch(sel) { case '1' : /* bmodify |= manage_network(); */ break; case '2' : bmodify |= manage_serial(); break; case '3' : bmodify |=Server_config(); break; case 'F' : case 'f' : break; case 'E' : case 'e' : printf("Exit Network Config"); break; } }//if(bmodify) evb_soft_reset(); } bmodify = 1; bmodify = 2; } } //------------------------------------------------------------------------------------------------ //------------------------------------------------------------ void get_net_conf(void) { NetConf.sip = (DEFAULT_NET_SIP); NetConf.gwip= (DEFAULT_NET_GWIP); NetConf.sn = (DEFAULT_NET_SN); NetConf.l_port = (DEFAULT_LOCAL_PORT); NetConf.mode = DEFAULT_MODE; } //----------------------------------------------------------------------- //--------------------------------------------------------------------------------------- static u_char manage_serial(void) { u_char dataprm,timeout; u_char choice=0,rtn; u_int BAUD; set_serialconf(); while(choice != 'd' && choice != 'D') { printf("nr-------------------------------nr nSerial Configration Menunr------------------------------nra.Baud ratenrb.Data parameternrc.Character wait timeoutnrd.exit nr"); scanf("%c",&choice); switch(choice) { case 'a': case 'A': printf("nr Existing Value = %d",(Serial_conf.baud)); printf("nr Enter new value ="); scanf("%d",&BAUD); Serial_conf.baud= (BAUD); rtn = 1; break; case 'b': case 'B': Data_parameters(); printf("nr Existing Value = %c",(Serial_conf.dataparameter)); printf("nr Enter new value ="); scanf("%c",&dataprm); Serial_conf.dataparameter= (dataprm); rtn = 1; break; case 'c': case 'C': printf("nr Existing Value = %c",(Serial_conf.conn_timeout)); printf("nr Enter new value ="); scanf("%c",&timeout); Serial_conf.conn_timeout= (timeout); rtn = 1; break; case 'd': case 'D': //set_netconf(&NetConf); printf("Exit Serial Config"); break; case 0x1B:printf("nrUser canceled."); break; } } return rtn; } //---------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------ static u_char Server_config(void) { set_server_confg(); while(select != 'f' && select != 'F') { if(NetConf.mode == '0') { printf("nr n Server Configration Menu for TCPnr a.IP Filteringnrb.Start Mode 0= auto mode,1=manual mode,2=input char modenr c.Remote IP addressnr d.Remote port numbernr e.Disconnect active connection(manualconnct mode)nr f.Exitnr"); scanf("%c",&select); switch(select) { case 'a': case 'A': print_server(select); rtns = 1; break; case 'b': case 'B': print_server(select); rtns = 1; break; case 'c': case 'C': print_server(select); rtns = 1; break; case 'd': case 'D': print_server(select); rtns = 1; break; case 'e': case 'E': print_server(select); rtns = 1; break; case 'f': case 'F': //set_netconf(&NetConf); printf("Exit Server Config"); break; } } } return rtns; } //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------- void Data_parameters(void) { printf("nr 1.N(No Parity),8(Data bit),1(Stop bit)(default)" "nr2.E(Even Parity),7(Data bit),1(Stop bit)" "nr 3.O(Odd Parity),7(Data Bits),1(Stop Bit)" "nr 4.E(Even Parity),8(Data bit),1(Stop bit)" "nr 5.O(Odd Parity),8(Data bit),1(Stop bit)" "nr 6.N(No Parity),8( Data bit),2(Stop bit)" "nr 7.E(Even Parity),7(Data bit),2(Stop bits)" "nr 8.O(Odd Parity),7(Data bit),2(Stop bits)" "nr 9.M(Mark Parity),8(Data bit),1(Stop bit)" "nr 0.S(Space Parity),8(Data bit),1(Stop bit)"); } //--------------------------------------------------------------------------------------------------- void set_serialconf(void) { Serial_conf.baud=DEFAULT_BAUD; Serial_conf.dataparameter=DEFAULT_DATA_PARM; Serial_conf.conn_timeout=DEFAULT_TIMEOUT; } //---------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------- void set_server_confg(void) { Server_Conf.rip=DEFAULT_RIP; Server_Conf.ip_fltng=DEFAULT_IPFILTERING; Server_Conf.r_port=DEFAULT_RPORT; Server_Conf.startmode=DEFAULT_SMODE; Server_Conf.DISS_conn=DEFAULT_DISCNCT; } /* insert third block here*/ //------------------------------------------------------------------------------------------------------------- // UART0_Init //-------------------------------------------------------------------------------------------------------------------- void UART0_Init (void) { SCON0 = 0x10; // SCON0: 8-bit variable bit rate // level of STOP bit is ignored // RX enabled // ninth bits are zeros // clear RI0 and TI0 bits if (SYSCLK/BAUDRATE/2/256 < 1) { TH1 = -(SYSCLK/BAUDRATE/2); CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx CKCON |= 0x08; } else if (SYSCLK/BAUDRATE/2/256 < 4) { TH1 = -(SYSCLK/BAUDRATE/2/4); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01 CKCON |= 0x01; } else if (SYSCLK/BAUDRATE/2/256 < 12) { TH1 = -(SYSCLK/BAUDRATE/2/12); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 00 } else { TH1 = -(SYSCLK/BAUDRATE/2/48); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10 CKCON |= 0x02; } } //------------------------------------------------------------------------------------------------------------ // timer initialization //------------------------------------------------------------------------------------------------------------------- void Timer1_Init (void) { TL1 = TH1; // init Timer1 TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload TMOD |= 0x20; TR1 = 1; // START Timer1 TX_Ready = 1; // Flag showing that UART can transmit IP |= 0x10; // Make UART high priority ES0 = 1; // Enable UART0 interrupts } //----------------------------------------------------------------------------- void PORT_Init (void) { P0MDOUT |= 0x10; // Enable UTX as push-pull output XBR0 = 0x01; // Enable UART on P0.4(TX) and P0.5(RX) XBR1 = 0x40; // Enable crossbar and weak pull-ups } //----------------------------------------------------------------------------- // SYSCLK_Init //---------------------------------------------------------------------------- void SYSCLK_Init (void) { OSCICN |= 0x03; // Configure internal oscillator for // its maximum frequency RSTSRC = 0x04; // Enable missing clock detector } //----------------------------------------------------------------------------- void print_server(u_char bits) { } |
Topic | Author | Date |
Program hangs at one point - 8051F340 | 01/01/70 00:00 | |
Assembly window | 01/01/70 00:00 | |
hyper terminal interface | 01/01/70 00:00 | |
Stack size? | 01/01/70 00:00 | |
Stack size | 01/01/70 00:00 | |
Stack Management | 01/01/70 00:00 | |
Watchdog | 01/01/70 00:00 | |
stack and preview.. | 01/01/70 00:00 | |
Limited stack | 01/01/70 00:00 | |
Where is the UART ISR? | 01/01/70 00:00 | |
ISR for UART | 01/01/70 00:00 | |
ISR for UART? | 01/01/70 00:00 | |
why "TI0=1;" is required | 01/01/70 00:00 | |
No, it isn't | 01/01/70 00:00 | |
Solved - I guess | 01/01/70 00:00 | |
'polling' is NOT "standard C" | 01/01/70 00:00 | |
You are right Erik.. | 01/01/70 00:00 | |
Thought I will thank you individually..![]() | 01/01/70 00:00 | |
Disable watchdog | 01/01/70 00:00 | |
and in Keil it is: | 01/01/70 00:00 | |
Status : WDT disabling in the status worked | 01/01/70 00:00 |