|
51單片機顯示名字學(xué)號身高體重等,C語言,完整包
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #include<reg51.h>
- #include<lcd1602.h>
- #define uchar unsigned char
- unsigned char x[]="SG,TZ";
- unsigned char y[]="ms20190404705";
- #define uint unsigned int
- sbit LCD_RS =P3^0;
- sbit LCD_RW =P3^1;
- sbit LCD_E =P3^2;
- #define LCD_ch P1
- //
- void delay(uint i)
- {
- while(i--);
- }
- // 寫指令進(jìn)入LCD1602
- void LCD_command()
- {
- LCD_RS=0;
- LCD_RW=0;
- LCD_E=0;
- delay(200);
- LCD_E=1;
- }
- // 把數(shù)據(jù)寫入LCD1602
- void LCD_data()
- {
- LCD_RS=1;
- LCD_RW=0;
- LCD_E=0;
- delay(200);
- LCD_E=1;
- }
- //
- void Init_LCD(void) //初始化液晶
- {
- LCD_ch =0x01; //清屏
- LCD_command();
- LCD_ch =0x38; //8位顯示
- LCD_command();
- LCD_ch =0x0c; //開顯示,關(guān)光標(biāo),關(guān)閃爍
- LCD_command();
- LCD_ch =0x06;
- LCD_command();
- }
- // 將數(shù)據(jù)顯示在第i行第j列
- void LCD_dis(uchar i,uchar j,uchar ch)
- {
- uchar addr;
- if(i==0) addr=0x80+j; //設(shè)置第一行
- else addr=0xc0+j; //設(shè)置第二行
- LCD_ch=addr;
- LCD_command();
- LCD_ch=ch;
- LCD_data();
- }
- void main()
- {
- unsigned int i,j;
- Init_LCD();
- while(1)
- {
- for(i=0;i<17;i++)
- {
- //LCD_dis(1,i,0x30+i);
- //LCD_dis(0,i,i+'0');
- //LCD_dis(1,i,i+'A');
- LCD_dis(1,i,x[i]); //顯示數(shù)組內(nèi)容
- delay(5000);
- }
- for(j=0;j<19;j++)
- {
- LCD_dis(0,j,y[j]);
- delay(5000);
- }
- }
- }
復(fù)制代碼
Keil代碼與Proteus仿真下載:
顯示名字學(xué)號.7z
(36.7 KB, 下載次數(shù): 27)
2022-1-20 18:35 上傳
點擊文件名下載附件
|
評分
-
查看全部評分
|