??? 08/23/06 23:57 Modified: 08/24/06 00:15 Read: times |
#122862 - Something is not right |
Greeting all members,
Please don't laugh because I'm a novice in C programming. I've done some reading but still not confident enough to write a big C program from scratch. I've done some programming in assembly and had no problem so far. As I think learning C is the good way to go, so I start rewriting all assembly programs that I wrote before as the way to practice my C programming. So I start out with a simple LCD control program. On the same hardware, the assembly code works flawlessly, but the C code I just wrote doesn't do anything. I'm having hard time to figure out what wrong with this piece of code. And there is one strange thing I'm experiencing is the break point. I'm currently using Ceibo DS-51 Emulator in conjunction with uVision2 IDE, with assembly code I can set break point anywhere and single step into any sub routine as I please, I can also do the same in Simulator mode, but when I switch to Emulator mode and run C code then I can't use single step into sub routine any more. For this reason I don't know how the code works. In simulator it seems to be OK. This is the code, any inputs, suggestions would be greatly appreciated. Thank you advance. /*----------------------------------------------------------------------------------*/ /* File Name: Main /* Processor: 87C752 /* ToolChain: Keil C51 V8.0 /* Author : T.L /* Version : 1.0 /* Date : 08/22/06 /*----------------------------------------------------------------------------------*/ #pragma code #pragma aregs #pragma db #include <Reg752.h> #include <stdio.h> /*----------------------------------------------------------------------------------*/ /* Global Constants /*----------------------------------------------------------------------------------*/ #define SysClk 12000000 // 12MHz #define True 1 #define False 0 #define Lcd P3 sbit Rs = P0^0; sbit Rw = P0^1; sbit En = P0^2; /*----------------------------------------------------------------------------------*/ /* Function prototypes /*----------------------------------------------------------------------------------*/ void Main (void); void Lcd_Init (void); void Lcd_Cmd (unsigned char Cmd); void Lcd_Dat (unsigned char Dat); void Delay_mS (unsigned int mS); void Delay_uS (unsigned int uS); /*----------------------------------------------------------------------------------*/ /* Global Variables /*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/ /* Main Routine /*----------------------------------------------------------------------------------*/ void Main (void) { P0 = 0xff; //Use P0 lower nibble for Lcd Ctrl P1 = 0xff; P3 = 0xf0; //Use P3 lower nibble for Lcd Data Lcd_Init (); Delay_mS (5); //Delay 5ms while (1) { Lcd_Dat (0x41); //Test character Delay_mS (5); //Delay 5ms } } /*----------------------------------------------------------------------------------*/ void Lcd_Init (void) { unsigned char i; i = 3; while (i) { Lcd_Cmd (0x28); //2 line 4 bit Lcd_Cmd (0x0f); //Display, Cursor, and blink on Lcd_Cmd (0x06); //Increment, no shift i--; } Lcd_Cmd (0x01); //Clear Lcd Delay_mS (2); //Some delay } /*----------------------------------------------------------------------------------*/ void Lcd_Cmd (unsigned char Cmd) { Rs = 0; Rw = 0; En = 1; Lcd = (Cmd & 0xf0) >> 4; //Write high nibble En = 0; En = 1; Lcd = (Cmd & 0x0f); //Write low nibble En = 0; Delay_uS (50); //Delay 50us } /*----------------------------------------------------------------------------------*/ void Lcd_Dat (unsigned char Dat) { Rs = 1; Rw = 0; En = 1; Lcd = (Dat & 0xf0) >> 4; //Write high nibble En = 0; En = 1; Lcd = (Dat & 0x0f); //Write low nibble En = 0; Delay_uS (50); //Delay 50us } /*----------------------------------------------------------------------------------*/ void Delay_mS (unsigned int mS) { unsigned int i; for (i = 0; i < mS; i++); { TH = -(SysClk/12/1000) >> 8; //Overflow @ 1ms TL = -(SysClk/12/1000); // TR = 1; // Start Timer0 while (!TF); // Poll overflow flag TR = 0; // Stop Timer0 TF = 0; // Clear flag } } /*----------------------------------------------------------------------------------*/ void Delay_uS (unsigned int uS) { TH = -uS >> 8; // TL = -uS; // TR = 1; // Start Timer0 while (!TF); // Poll overflow flag TR = 0; // Stop Timer0 TF = 0; // Clear flag } /*----------------------------------------------------------------------------------*/ |
Topic | Author | Date |
Something is not right | 01/01/70 00:00 | |
01/01/70 00:00 | ||
Houston, we have a problem | 01/01/70 00:00 | |
Something is not right | 01/01/70 00:00 | |
Problem solved![]() | 01/01/70 00:00 |