We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
The following codes are for initializing the LCD display and directly copied from my program, but when those codes under debugging using software simulator, why the line 6 & line 12 always are non-executable code (invalid break points)? What are the possible reasons? void DispInit ( unsigned char maxrows, unsigned char maxcols) { 1. DispInitPort(); 2. DispMaxRows = maxrows; 3. DispMaxCols = maxcols; 4. OS_Delay(100); 5. DispSel(DISP_SEL_CMD_REG); 6. DispDataWr(0x30); 7. OS_Delay (2); 8. DispSel(DISP_SEL_CMD_REG); 9. DispDataWr(0x30); 10. OS_Delay(150); 11. DispSel(DISP_SEL_CMD_REG); 12. DispDataWr(0x30); 13. OS_Delay(2); 14. DispSel(DISP_SEL_CMD_REG); 15. DispDataWr(0x08); 16. OS_Delay(2); 17. DispSel(DISP_SEL_CMD_REG); 18. DispDataWr(0x08); 19. OS_Delay(2); } Please help me, it is time consuming & really killing
I've never used LCDs so this may be dumb question. Is DispDataWr() an actual function call or a macro that writes data to a variable? If it is a macro you might be able to fix the problem by declaring the variable as volatile so it is not obtimized out. -Walt
Thank you for your responds. The following codes is the DispDataWr() function: static void DispDataWr(unsigned char val) { P21_PIN = 0; // write operation P22_PIN = 1; // give operation start signal _nop_ (); _nop_ (); // wait P1 = val; // write value P22_PIN = 0; P1 = 0xff; // DATA_PORT is input [prevent I/O-Port from demage] } and the OS_Delay function is the following codes: void OS_Delay ( int n ) { int i; while( n --) { for(i == 0; i < 125; i++ ) {;} } }
Please remember to use the 'pre' and '/pre' tags around code, like is says in the instructions. Note that your code contains the sequence
DispDataWr(0x30); OS_Delay (2);
Thank you Walt Conley and Andy Neil . You are absolutely right. After I have changed the function DispDataWr from: static void DispDataWr(unsigned char val) to: static void DispDataWr(volatile unsigned char val), problems seem have been resolved. By the way the optimization setting I am using is level 8 ( reuse common entry code).