BubbleGum
Newbie level 1
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 #include <htc.h> #include <pic.h> __CONFIG ( 0x3F32 ); #define rs RC4 #define e RC5 #define lcd_data PORTB void send_config(unsigned char data); void delay(unsigned long data); void send_string(const char *s); void lcd_clr(void); void lcd_goto(unsigned char data); void send_char(unsigned char data); unsigned char location=1; void main(void) { TRISB = 0b00000000; TRISC = 0b10000000; send_config(0b00000001); //clear display at lcd send_config(0b00000010); //lcd return to home send_config(0b00000110); //entry mode-cursor increase 1 send_config(0b00001100); //display on, cursor off and cursor blink off send_config(0b00111000); //function set lcd_clr(); lcd_goto(0); send_string("ND2/11/CME"); lcd_goto(20); send_string("MKJB"); delay(200000); lcd_clr(); } void send_config(unsigned char data) { rs=0; lcd_data = data; e=1; delay(50); e=0; delay(50); } void lcd_clr(void) { send_config(0x01); delay(600); } void delay(unsigned long data) { for( ;data>0;data--); } void lcd_goto(unsigned char data) //set the location of the lcd cursor { //if the given value is (0-15) the if(data<16) //cursor will be at the upper line { //if the given value is (20-35) the send_config(0x80+data); //cursor will be at the lower line } //location of the lcd cursor(2X16): else // ----------------------------------------------------- { // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| | data=data-20; // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| | send_config(0xc0+data); // ----------------------------------------------------- } } void send_string(const char *s) //send a string to display in the lcd { unsigned char i=0; while (s && *s)send_char (*s++); } void send_char(unsigned char data) //send lcd character { rs=1; //set lcd to display mode lcd_data=data; //lcd data port = data e=1; //pulse e to confirm the data delay(10); e=0; delay(10); }
is it okay?