此为程序,求大神帮助
#include
#include
#define SYSCLK 24500000
#define uchar unsigned char
#define uint unsigned int
sfr16 TMR2RL = 0xca; // Timer2 reload value
sfr16 TMR2 = 0xcc; // Timer2 counter
sfr16 ADC0 = 0xbd; // ADC0 result
sbit rs=P1^5;
sbit wr=P1^6;
sbit lcden=P1^7;
uchar shuzi[] = {"0123456789."};
uint i,j; // LED='1' means ON
void SYSCLK_Init (void)
{
OSCICN = 0x87; // configure internal oscillator for
// 24.5MHz
RSTSRC = 0x04; // enable missing clock detector
}
void PORT_Init (void)
{
XBR0 = 0x01; // Enable UART0
XBR1 = 0x40; // Enable crossbar and weak pull-ups
//P0MDOUT |= 0x10; // Set TX pin to push-pull
P1MDOUT = 0xE0; // enable LED as a push-pull output
P1MDIN &= 0xFc; // set P1.1 as an analog input
P1SKIP |= 0x03; // skip P1.1 pin
P2MDOUT =0xFF;
}
void ADC0_Init (void)
{
ADC0CN = 0x03; // ADC0 disabled, normal tracking,
// conversion triggered on TMR2 overflow
REF0CN = 0x13; // Enable on-chip VREF = 2.2v and buffer
ADC0MX = 0x08; // Set P1.1 as positive input
ADC0CF = ((SYSCLK/3000000)-1)<<3; // set SAR clock to 3MHz
ADC0CF |= 0x00; // right-justify results
EIE1 |= 0x08; // enable ADC0 conversion complete int.
AD0EN = 1; // enable ADC0
}
void delay(uint x)
{
for(i=x;i>0;i--)
{
for(j=120;j>0;j--);
}
}
void write_com(uchar com)
{
rs=0;
wr=0;
lcden=0;
P2=com;
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar dat)
{
rs=1;
wr=0;
lcden=0;
P2=dat;
lcden=1;
delay(5);
lcden=0;
}
void init()
{
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0f);
}
void address(uchar x,uchar y)
{
if(x%2==1)
write_com(0x80+(y%16)-1);
else
write_com(0x80+0x40+(y%16)-1);
}
void main()
{
unsigned long mv=0;
uint num[4]; init();
SYSCLK_Init ();
PORT_Init ();
ADC0_Init();
while(1)
{
AD0INT=0;
AD0BUSY=1;
while(AD0INT==0)
{
mv=ADC0;
}
mv= (mv * 220)/4095;
num[0]=mv/100;
mv=mv-num[0]*100;
num[2]=mv/10;
num[3]=mv-(num[2]*10);
num[1]=10;
address(2,1);
for(i=0;i<4;i++)
{
write_data(shuzi[num]);
}
}
while(1);
}
先看电路是不是有问题,再看初始化程序是不是有问题。
天地庄周马;江湖范蠡船。
个性签名还是放QQ号吧,2060347305,添加说明EEworld好友
楼主,应该搞的是lcd1602,所以您除了要注意初始化,还要注意背光哦。这个lcd的程序网上一大把的,只要您看懂时序,理解了就没问题了。特别再次声明的是,背光需要注意哦。还有硬件电路也是需要check哦