/********************************************************************* #define PORT_busy PB_DDR=0x00;PB_CR1=0xff; #define busy PB_IDR #define PORT_OUT PB_DDR=0xff;PB_CR1=0xff; #define PORT PB_ODR #define EN_SET sbi(PC_DDR,5);sbi(PC_CR1,5);sbi(PC_ODR,5); #define EN_CLR sbi(PC_DDR,5);sbi(PC_CR1,5);cbi(PC_ODR,5); #define RW_SET sbi(PC_DDR,6);sbi(PC_CR1,6);sbi(PC_ODR,6); #define RW_CLR sbi(PC_DDR,6);sbi(PC_CR1,6);cbi(PC_ODR,6); #define RS_SET sbi(PE_DDR,5);sbi(PE_CR1,5);sbi(PE_ODR,5); #define RS_CLR sbi(PE_DDR,5);sbi(PE_CR1,5);cbi(PE_ODR,5); _Bool lcd1602_busy(void) { _Bool result; RS_CLR; RW_SET; EN_SET; delay(5); PORT_busy; result=(busy & 0x80); EN_CLR; return result; } void lcd1602_write_com(u8 com) { while(lcd1602_busy()); RS_CLR; RW_CLR; EN_CLR; PORT_OUT; PORT=com; EN_SET; delay(5); EN_CLR; } void lcd1602_write_data(u8 dat) { while(lcd1602_busy()); RS_SET; RW_CLR; EN_CLR; PORT_OUT; PORT=dat; EN_SET; delay(5); EN_CLR; } void lcd1602_gotoxy(u8 x,u8 y) { u8 add; if(y==0) add=0x80+x; else add=0xc0+x; lcd1602_write_com(add); } void lcd1602_init(void) { delay(100); lcd1602_write_com(0x38); lcd1602_write_com(0x0c); lcd1602_write_com(0x06); lcd1602_write_com(0x01); } void lcd1602_display(void) { for(num=0;num<12;num++) { lcd1602_write_data(table[num]); delay(5); } } |
以上资料由微雪电子整理并发布,未经许可不得转载,否则追究相应责任!