|
基于AT89C51單片機,使用LM016L顯示屏
通過KEIL編寫輸入學(xué)號+拼音姓名,輸出HEX文件到
- #include<reg52.h>
- int init(); //聲明初始化函數(shù)
- int write_com(unsigned char);//聲明寫命令函數(shù)
- int write_date(unsigned char);//聲明寫數(shù)據(jù)函數(shù)
- int delay(unsigned char);//聲明延遲函數(shù)
- unsigned char x;
- sbit RS = P1^0;
- sbit RW = P1^1;
- sbit EN = P1^2;
- unsigned char code table[]="15829806!";
- unsigned char code table1[]="UANG DREG XEQNG";
- int main(void)//主函數(shù)
- {
- init();
- write_com(0x80);
- for(x=0;x<8;x++)
- {
- write_date(table[x]);
- delay(150);
- }
- write_com(0x80+0x40);
- for(x=0;x<17;x++)
- {
- write_date(table1[x]);
- delay(150);
- }
- while(1);
- return 0;
- }
- int init()//初始化函數(shù)體
- {
- EN = 0;
- write_com(0X38);//設(shè)置16*2顯示,5*7點陣,8位數(shù)據(jù)接口
- write_com(0X0C);//設(shè)置開顯示,不顯示光標(biāo)
- write_com(0X06);//寫一個字符時,整屏右移
- write_com(0X01);//顯示清零
- return 0;
- }
- int write_com(unsigned char com)//寫命令的函數(shù)體
- {
- RS = 0;
- RW = 0;
- P0 = com;
- delay(5);
- EN = 1;
- delay(5);
- EN = 0;
- return 0;
- }
- int write_date(unsigned char date)//寫數(shù)據(jù)的函數(shù)體
- {
- RS = 1;
- RW = 0;
- P0 = date;
- delay(5);
- EN = 1;
- delay(5);
- EN = 0;
- return 0;
- }
- int delay(unsigned char xms)
- {
- unsigned char x,y;
- for(x=xms;x>0;x--)
- for(y=110;y>0;y--);
- return 0;
- }
復(fù)制代碼
單片機中運行即可
|
|