Untitled
#include<reg51.h> #define DATA_PINS P0 sbit LED_PIN = P2^0; sbit RS_PIN = P2^1; sbit EN_PIN = P2^2; sbit RW_PIN = P2^3; void delay(unsigned int delay); void lcd_init(); void send_command(char command); void send_data(char single_char); void send_text(char *text); int main(void){ while(1){ lcd_init(); send_command(0x01); delay(100); send_text("Test 1"); delay(10000); send_command(0xC0); send_text("Test 2"); delay(10000); } } void delay(unsigned int delay){ unsigned long i; for(i=0;i<delay;i++); } void lcd_init(){ RW_PIN = 0; send_command(0x38); send_command(0x0e); send_command(0x01); send_command(0x06); send_command(0x0c); send_command(0x80); } void send_command(char command){ DATA_PINS = command; RS_PIN = 0; RW_PIN = 0; EN_PIN = 1; delay(10); EN_PIN = 0; } void send_data(char single_char){ DATA_PINS = single_char; RS_PIN = 1; RW_PIN = 0; EN_PIN = 1; delay(10); EN_PIN = 0; } void send_text(char *text){ while(*text) send_data(*text++); }
Leave a Comment