求助大佬帮忙看看,目的是做一个检测光亮度的器件,目前检测系统没有问题,但原定的显示部分(1602)无法正常显示代码如下
- #include <REG52.H>
- #include <math.h>
- #include <stdio.h>
- #include <INTRINS.H>
- #define uchar unsigned char
- #define uint unsigned int
- #define DataPort P0
- sbit LCM_RS=P2^7;
- sbit LCM_RW=P2^6;
- sbit LCM_EN=P2^5;
- sbit k1=P1^5;
- sbit led=P3^7;
- sbit beep=P3^6;
- sbit light = P1^1;
- void delay(unsigned int k);
- void InitLcd();
- void WriteDataLCM(uchar dataW);
- void WriteCommandLCM(uchar CMD,uchar Attribc);
- void DisplayOneChar(uchar X,uchar Y,uchar DData);
- void LCD_Clear();
- void InitLcd()
- {
- WriteCommandLCM(0x38,1);
- WriteCommandLCM(0x08,1);
- WriteCommandLCM(0x01,1);
- WriteCommandLCM(0x06,1);
- WriteCommandLCM(0x0c,1);
- }
- void WaitForEnable(void)
- {
- DataPort=0xff;
- LCM_RS=0;LCM_RW=1;_nop_();
- LCM_EN=1;_nop_();_nop_();
- while(DataPort&0x80);
- LCM_EN=0;
- }
- void WriteCommandLCM(uchar CMD,uchar Attribc)
- {
- if(Attribc)WaitForEnable();
- LCM_RS=0;LCM_RW=0;_nop_();
- DataPort=CMD;_nop_();
- LCM_EN=1;_nop_();_nop_();LCM_EN=0;
- }
- void WriteDataLCM(uchar dataW)
- {
- WaitForEnable();
- LCM_RS=1;LCM_RW=0;_nop_();
- DataPort=dataW;_nop_();
- LCM_EN=1;_nop_();_nop_();LCM_EN=0;
- }
- void DisplayOneChar(uchar X,uchar Y,uchar DData)
- {
- Y&=1;
- X&=15;
- if(Y)X|=0x40;
- X|=0x80;
- WriteCommandLCM(X,0);
- WriteDataLCM(DData);
- }
- void delay(unsigned int k)
- {
- unsigned int i,j;
- for(i=0;i<k;i++)
- {
- for(j=0;j<121;j++)
- {;}
- }
- }
- void LCD_Clear(void)
- {
- WriteCommandLCM(0x01);
- delay(20);
- }
- void main()
- {
- InitLcd()
- LCD_Clear();
- DisplayOneChar(0,1,'d');
- DisplayOneChar(1,1,'a');
- DisplayOneChar(2,1,'n');
- led=0;
- beep=1;
- k1=0;
- WriteCommandLCM(0x08);
- while(1)
- {
- if(light==0)
- {
- led=1;
- beep=0;
- }
- }
- }
复制代码
|