Keil4编写环境:A/D数模转换和按键应用操作显示到Lcd1602上,子程序Lcd1602.c,keyboard.c,I2C.c程序略,跪求主程序
程序要求实现:按上键查询设定的电压值上下限
按下键查询当前的电压值(当前电压值是滑动变阻器所配置的电压值)
数据采集器件用的是PCF8591测AIN0的值
为什么我的主函数这样写,在51液晶上按上下键没有任何显示,跪求主函数,开发板是金三角开发板
#include <reg52.h>
sbit BUZZ = P1^6;
bit flag300ms = 1;
bit enBuzz = 0;
unsigned char T0RH = 0;
unsigned char T0RL = 0;
unsigned int CountDown = 0;
void ConfigTimer0(unsigned int ms);
unsigned char GetADCValue(unsigned char chn);
void ValueToString(unsigned char *str, unsigned char val);
extern void I2CStart();
extern void I2CStop();
extern void KeyScan();
extern void KeyDriver();
extern unsigned char I2CReadACK();
extern unsigned char I2CReadNAK();
extern bit I2CWrite(unsigned char dat);
extern void InitLcd1602();
extern void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);
void main()
{
EA = 1;
ConfigTimer0(10);
InitLcd1602();
// LcdShowStr (0, 0, "moli");
while(1)
{
KeyDriver();
}
}
unsigned char GetADCValue (unsigned char chn)
{
unsigned char val;
I2CStart();
if (!I2CWrite (0x48<<1))
{
I2CStop();
return 0;
}
I2CWrite (0x40 | chn);
I2CStart();
I2CWrite ((0x48<<1) | 0x01);
I2CReadACK();
val = I2CReadNAK();
I2CStop();
return val;
}
void ValueToString(unsigned char *str, unsigned char val)
{
val = (val * 25) / 55;
str[0] = (val/10) + '0';
str[1] = '.'; //С????
str[2] = (val%10) + '0';
str[3] = 'V';
str[4] = '\0';
}
void KeyTaAction()
{
unsigned char val;
unsigned char str[10];
InitLcd1602();
LcdShowStr (0, 0, "TABANXINHAO");
while (1)
{
if (flag300ms)
{
flag300ms = 0;
val = GetADCValue(0);
ValueToString(str, val);
LcdShowStr(0, 1, str);
if (val >= 200)
{
enBuzz = 1;
if (enBuzz)
BUZZ = ~BUZZ;
}
else
BUZZ = 1;
}
}
}
void KeyAction (unsigned char keycode)
{
if(keycode == 0x26)
{
KeyTaAction();
}
else if (keycode == 0x28)
{
LcdShowStr (0, 0, "MAX");
LcdShowStr (0, 1, 2^5);
LcdShowStr (6, 0, "MIN");
LcdShowStr (6, 1, 0^0);
}
}
void ConfigTimer0(unsigned int ms)
{
unsigned long tmp;
tmp = 11059200 / 12;
tmp = (tmp * ms) / 1000;
tmp = 65536 - tmp;
tmp = tmp + 12;
T0RH = (unsigned char)(tmp >> 8);
T0RL = (unsigned char)tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RH;
TL0 = T0RL;
ET0 = 1;
TR0 = 1;
}
void InterruptTimer0() interrupt 1
{
static unsigned char tmr300ms = 0;
TH0 = T0RH;
TL0 = T0RL;
tmr300ms++;
if (tmr300ms >= 30)
{
tmr300ms = 0;
flag300ms = 1;
}
}
|