}
if(KEY2 == 0) { delay(); if(KEY2 == 0) { P0 = ~14;
}
}
if(KEY3 == 0) { delay(); if(KEY3 == 0) { P0 = ~15; }
}
if(KEY4 == 0) { delay(); if(KEY4 == 0) { P0 = ~16; }
}
while((KEY1 == 0)||(KEY2 == 0)||(KEY3 == 0)||(KEY4 == 0));
}
}
void delay() { unsigned int i = 1000; while(i--);
}
8课未完待续
Lesson 12 指针与LCD1602初识
57分钟后为1602
程序一:用显示字符的形式在LCD上显示 字符串与数字 #include
//第四行检测完
sbit RS = P1^0; sbit RW = P1^1; sbit EN = P1^5; sbit BUSY = P0^7; //等待繁忙标志 void wait() { }
void w_dat(unsigned char dat) { }
void w_cmd(unsigned char cmd) { }
void init_lcd1602(void)
wait(); EN = 0; P0 = cmd; RS = 0; RW = 0; EN = 1; EN = 0; wait(); EN = 0; P0 = dat; RS = 1; RW = 0; EN = 1; EN = 0; P0 = 0XFF; do { }
while(BUSY == 1); EN = 0;
RS = 0; RW = 1; EN = 0; EN = 1;
{ } main() { }
程序二:用发送字符串的形式在LCD上显示字符串。 #include
sbit RS = P1^0; sbit RW = P1^1; sbit EN = P1^5; sbit BUSY = P0^7;
unsigned char code word1[] = {\ my god!%unsigned char code word2[] = {\//等待繁忙标志 void wait() {
while(1); w_cmd(0xc0); w_dat(1+'0'); w_dat(2+'0'); w_dat(3+'0'); w_dat(4+'0'); w_dat(5+'0'); w_dat(6+'0'); w_dat(7+'0'); w_cmd(0x80); w_dat(65); w_dat(66); w_dat(67); w_dat(68); w_dat(69); w_dat(70); w_dat(71);
//w_dat('A');
init_lcd1602(); w_cmd(0x38); w_cmd(0x0c); w_cmd(0x06); w_cmd(0x01);
}
P0 = 0XFF; do { }
while(BUSY == 1); EN = 0;
RS = 0; RW = 1; EN = 0; EN = 1;
void w_dat(unsigned char dat) { }
void w_cmd(unsigned char cmd) { }
void init_lcd1602(void) { }
void w_string(unsigned char addr_start, unsigned char *p)
w_cmd(0x38); w_cmd(0x0c); w_cmd(0x06); w_cmd(0x01); wait(); EN = 0; P0 = cmd; RS = 0; RW = 0; EN = 1; EN = 0; wait(); EN = 0; P0 = dat; RS = 1; RW = 0; EN = 1; EN = 0;
{ } main() { }
while(1);
w_string(0x80,word1); w_string(0xc0,word2); init_lcd1602(); w_cmd(addr_start); while(*p != '\\0') { }
w_dat(*p++);
百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库单片机听课笔记1-8课(金沙滩2024年更新)(6)在线全文阅读。
相关推荐: