uint v;
void matrixkeyscan() ; //矩阵 void delay(int ms) {
while(ms--) {
uchar i; for(i=0;i<150;i++) { _nop_(); _nop_(); _nop_(); _nop_(); } } }
void matrixkeyscan() {
uchar temp; P2=0xfe; temp=P2;
temp=temp&0xf0; if(temp!=0xf0) { delay(10); temp=P2; temp=temp&0xf0; if(temp!=0xf0) { temp=P2; switch(temp) {
case 0xee:key=1,index = 0;break; case 0xde:key=2,index = 0;break; case 0xbe:key=3,index = 0;break; case 0x7e:key=4,index = 0;break; }
while(temp!=0xf0) { temp=P2; temp=temp&0xf0; } } }
P2=0xfd; temp=P2; temp=temp&0xf0; if(temp!=0xf0) { delay(10); temp=P2; temp=temp&0xf0; if(temp!=0xf0) { temp=P2; switch(temp) { case 0xed:key=5,index = 0; break; case 0xdd:key=2, index = 0, s++; break; case 0xbd:key=7;index = 0; break; case 0x7d:key=8;index = 0; break; } while(temp!=0xf0) { temp=P2; temp=temp&0xf0; } } } } }
void delay1(int ms) {
while(ms--) {
uchar y; for(y=0;y<100;y++) ; } } bit lcd_busy()
{ bit result;
LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; delayNOP();
result = (bit)(P0&0x80); LCD_EN = 0; return(result); }
void lcd_wcmd(uchar cmd)
{ while(lcd_busy()); LCD_RS = 0; LCD_RW = 0; LCD_EN = 0; _nop_(); _nop_(); P0 = cmd; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; }
void lcd_wdat(uchar dat)
{ while(lcd_busy()); LCD_RS = 1; LCD_RW = 0; LCD_EN = 0; P0 = dat; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; }
void lcd_init() {
lcd_wcmd(0x34); delay(5);
lcd_wcmd(0x30); delay(5);
lcd_wcmd(0x0C); //扩充指令操作 //基本指令操作 //显示开,关光标
delay(5);
lcd_wcmd(0x01); //清除LCD的显示内容 delay(5); }
void lcd_pos(uchar X,uchar Y) { uchar pos; if (X==1) {X=0x80;} else if (X==2) {X=0x90;} else if (X==3) {X=0x88;} else if (X==4) {X=0x98;} pos = X+Y ;
lcd_wcmd(pos); //显示地址 }
void photodisplay(uchar *bmp) {
uchar i,j;
lcd_wcmd(0x34); //写数据时,关闭图形显示
for(i=0;i<32;i++) {
lcd_wcmd(0x80+i); //先写入水平坐标值 lcd_wcmd(0x80); //写入垂直坐标值
for(j=0;j<16;j++) //再写入两个8位元的数据 lcd_wdat(*bmp++); delay1(1); }
for(i=0;i<32;i++) {
lcd_wcmd(0x80+i); lcd_wcmd(0x88);
for(j=0;j<16;j++) lcd_wdat(*bmp++); delay1(1); }
lcd_wcmd(0x36); //写完数据,开图形显示 }
void clr_screen() {
lcd_wcmd(0x34); //扩充指令操作 delay(5);
lcd_wcmd(0x30); //基本指令操作 delay(5);
lcd_wcmd(0x01); //清屏 delay(5); }
void bytecode() {
uchar s;
clr_screen(); lcd_wcmd(0x80); for(s=0;s<16;s++) {
lcd_wdat(0x30+s); }
lcd_wcmd(0x90); for(s=0;s<16;s++) {
lcd_wdat(0x40+s); }
lcd_wcmd(0x88); for(s=0;s<16;s++) {
lcd_wdat(0x50+s); }
lcd_wcmd(0x98); for(s=0;s<16;s++) {
lcd_wdat(0x60+s); } }
void main() {
uchar i,key1; index=40; v=1000; s=0;
//清屏
//设置显示位置为第一行 //设置显示位置为第二行 //设置显示位置为第三行 //设置显示位置为第四行
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库单片机实习报告(2)在线全文阅读。
相关推荐: