#include "N76E003.h"#include "SFR_Macro.h"#include "Function_define.h"#include "Common.h"#include "Delay.h"
#define KEY_E P03#define KEY_S P04#define KEY_I P05#define KEY_M P30#define NO_OF_LINE 2 ///< 2 line character LCD#define NO_OF_CHARACTER_PER_LINE 16 ///< 16 characters per line
/// LCD initialization commands for 8-bit mode#define LCD_INIT_COMMAND_1 0x30 ///< 8-bit interface#define LCD_INIT_COMMAND_2 0x30#define LCD_INIT_COMMAND_3 0x38#define LCD_INIT_COMMAND_4 0x0E ///< #define LCD_INIT_COMMAND_5 0x80 ///< Display ON, cursor OFF#define LCD_INIT_COMMAND_6 0x06 ///< Entry mode - no shift, auto increment#define LCD_INIT_COMMAND_7 0x00 ///< Clear LCD
#define D0_PIN P10#define D1_PIN P11 #define D2_PIN P12 #define D3_PIN P13#define D4_PIN P14 #define D5_PIN P15 #define D6_PIN P16 #define D7_PIN P17
#define RS_PIN P00#define EN_PIN P01#define LCD_LIGHT P02
#define LCD_DATA P1
#define LCD_INIT_DELAY 500 ///< Delay in milliseconds to be used in LCD initialization#define LCD_EN_DELAY 100 ///< Delay in milliseconds to be used in LCD data/command send
#define LINE_1 0x80 ///< Starting address of line 1#define LINE_2 0xC0 ///< Starting address of line 2 #define LINE_3 0x94 ///< Starting address of line 3 #define LINE_4 0xD4 ///< Starting address of line 4
#define CURSER_ON 0x0F ///< CURSER_ON & BLINKING#define CURSER_OFF 0x0C ///< CURSER_OFFchar key;char N1,N2,N3,N4,N5,N6,N7,N8,i;int y1,y2,y3,y4,y5;unsigned int x2,x3;unsigned long x,x1;
//void Delay(unsigned int j)void Delay(unsigned int j){ unsigned int i; for(i=0;i<j;i++);}
//---------------------------------------------- //------------------------------------------------
/// Sends data/command to character LCD/// @param[in] rawByte Byte to send /// @param[in] type COMMNAD or DATA
void SendByteToLcd(char rawByte){
RS_PIN=1; P1 = rawByte; EN_PIN=1; Delay(LCD_EN_DELAY); EN_PIN =0; Delay(LCD_EN_DELAY);}
void SendCMDToLcd(char rawByte){
RS_PIN =0; P1 = rawByte; EN_PIN=1; Delay(LCD_EN_DELAY); EN_PIN =0; Delay(LCD_EN_DELAY);}
void clrlcd() { SendCMDToLcd(0x00); Delay(LCD_EN_DELAY); SendCMDToLcd(CURSER_OFF); }
void PutCharacterOnLcd(char lineNumber, int characterPosition, char character) { SendCMDToLcd(lineNumber + characterPosition); ///< Set cursor position SendByteToLcd(character); ///< Send data characterPosition++; }
void PutStringOnLcd(char lineNumber, char stringStartPosition, char *string, int stringLength){ SendCMDToLcd(lineNumber + stringStartPosition); ///< Set cursor position while ((*string) && (stringLength > 0)) { SendByteToLcd(*string); ///< Send data string++; stringLength--; } SendCMDToLcd(CURSER_OFF); }
void InitLcd(void){ char tmp = 0; char lcdInitCommand[] = { LCD_INIT_COMMAND_1, LCD_INIT_COMMAND_2, LCD_INIT_COMMAND_3, LCD_INIT_COMMAND_4, LCD_INIT_COMMAND_5, LCD_INIT_COMMAND_6, LCD_INIT_COMMAND_7 };
D0_PIN = 0 ; D1_PIN = 0 ; D2_PIN = 0 ; D3_PIN = 0 ; D4_PIN = 0 ; D5_PIN = 0 ; D6_PIN = 0 ; D7_PIN = 0 ; /// Send LCD initialization commands for (tmp = 0; tmp < 7; tmp++) { SendCMDToLcd(lcdInitCommand[tmp]); Delay(LCD_INIT_DELAY); } LCD_LIGHT = 0;} char Kya_scan(){ if (KEY_E == 0){ Delay(500000); while (KEY_E ==0); return 'E'; } if (KEY_S == 0){ Delay(500000); while (KEY_S ==0); return 'S'; } if (KEY_I == 0){ Delay(500000); while (KEY_I ==0); return 'I'; } if (KEY_M == 0){ Delay(500000); while (KEY_M ==0); return 'M'; } return 'n'; } char GetKey(void) // Get key from user{ key = 'n'; // Assume no key pressed while(key=='n') // Wait untill a key is pressed key = Kya_scan(); // Scan the keys again and again return key; //when key pressed then return its value}void INTEGER_ASCII(unsigned long NUMBER){ int n1,n2,n3,n4,n5,n6; n1 =NUMBER%10; NUMBER/=10; n2 =NUMBER%10; NUMBER/=10; n3 =NUMBER%10; NUMBER/=10; n4 =NUMBER%10; NUMBER/=10; n5 =NUMBER%10; NUMBER/=10; n6 =NUMBER%10; N1= 0x30|n1; N2= 0x30|n2; N3= 0x30|n3; N4= 0x30|n4; N5= 0x30|n5; N6= 0x30|n6;}void main(void){
Set_All_GPIO_Quasi_Mode; // Define in Function_define.h InitLcd(); Delay(300) ; PutStringOnLcd(LINE_1, 0," Welcome " , 16); PutStringOnLcd(LINE_2, 0," SHINE " , 16); Timer0_Delay1ms(1000) ; clrlcd(); //enable global interrupt while(1){ x=100000; for( x=100000;x<999999;x++){ INTEGER_ASCII(x); PutCharacterOnLcd(LINE_1, 4, N6); PutCharacterOnLcd(LINE_1, 5, N5); PutCharacterOnLcd(LINE_1, 6, N4); PutCharacterOnLcd(LINE_1, 7, N3); PutCharacterOnLcd(LINE_1, 8, N2); PutCharacterOnLcd(LINE_1, 9, N1); Timer0_Delay1ms(1000) ; }}}
I recommend to:
- detail the problem that you face
- confirm the target in use
- and confirm the product and version in use
thanks for your valuable response,
I'm using N76E003 with 16x2 LCD to keil 5, i want display variable number on lcd,
i facing the problem some time lcd show % !, and some time like firts image lat to didgit automatic shited on 1 and 2 position of lcd.
i'm 200% sure one wiring because i'm successfully print A string or charter.
,
please reply
Sorry for the delay - I will forward your request to our corresponding expert, who will reply to you after returning from his vacation beginning of September.
Thanks for your patience.