本帖最后由 neuangel 于 2014-2-25 22:35 编辑
用的是89c51
单片机液晶用的是12864,显示为乱码,帮忙看看
/* lcd12864
液晶显示*/#include <reg52.h>#include<intrins.h>#define uint unsigned int #define uchar unsigned charuchar code table[]="I LIKE hhh! hello";uint num;sbit lcd_rs=P1^0; //4 sbit lcd_rw=P1^1; //5sbitlcd_en=P1^2; //6sbit lcd_rst=P1^3; //17sbit lcd_cs1=P1^6; //15sbit lcd_cs2=P1^7; //16
/*
函数声明 */void init();void delayms(uint);void write_com(uchar);void write_datas(uchar);void read_busy();
/*主函数*/void main(){ init(); lcd_cs1=1; lcd_cs2=1; for(num=0;num<18;num++) { write_datas(table[num]); // write_datas('o'); // delayms(1000); }}void read_busy(){ P0=0x00; lcd_rs=1; lcd_rw=0; lcd_en=1; while(P0&0x80); lcd_en=0;
}void init() //
初始化{ write_com(0x3f);//
开显示 write_com(0xc0); //
设置代码起始行为0 write_com(0xb8);//
设置页地址 x
地址 write_com(0x40); //
设置y
地址 write_com(0x80);//
设置列地址
}void delayms(uint z) //
延时函数{ uintx,y; for(x=z;x>0;x--) { for(y=100;y>0;y--); }
}void write_com(uchar com) //
写指令{// read_busy(); _nop_(); _nop_(); _nop_(); lcd_rs=0; lcd_rw=0;// delayms(4); P0=com;// delayms(5); lcd_en=1; delayms(5); lcd_en=0;}void write_datas(uchar datas) //
写数据{// read_busy(); _nop_(); _nop_(); _nop_(); lcd_rs=1; lcd_rw=0;// delayms(4); P0=datas;// delayms(5); lcd_en=1; delayms(5); lcd_en=0;}
一周热门 更多>