#include <STC12C5A60S2.H>
#include <pwmtiaoguang.H>
#include <intrins.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define ADC_POWER 0X80
#define ADC_FLAG 0X10
#define ADC_START 0X08
#define ADC_SPEEDLL 0X00
//12864液晶相关I/O设置
sbit RS=P2^0; //并行数据/控制字选择 H:数据 L:控制字
sbit RW=P2^1; //并行读/写选择 H:读 L:写
sbit E =P2^2; //并行读写使能 H有效,下降沿锁定数据
sbit PSB=P2^3; //串口,并口选择 H:并口 L:串口(开发板上引脚标识为CS1)
sbit RST=P2^5; //复位引脚 L:液晶复位
sbit SI=P3^0;
sbit CLK=P3^1;
uint Voitage_Value=0;
uchar Voltage_DatCount=0,Cnt=0,Disp_flag=0;
uint xdata Voltage_Dat[128]={0};
uchar xdata **Cepark[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code Graph[]={0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x20,0x04,0x40,0x10,0x50,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x7C,0x20,0x04,0x40,0x10,0x48,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3F,0xF8,0x44,0x50,0x04,0x40,0x20,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x50,0x04,0x40,0x24,0x5C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x08,0x20,0x48,0x88,0x7F,0xFC,0x45,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x04,0x40,0x51,0x04,0x44,0x44,0xF8,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFE,0x4A,0x02,0x44,0x44,0x10,0x5E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x88,0x44,0x44,0x23,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0xF0,0x44,0x88,0x44,0x44,0x40,0x44,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x10,0x44,0x88,0x7F,0xFC,0xFC,0x48,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x10,0x44,0x88,0x44,0x44,0x40,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0xF0,0x68,0x88,0x44,0x44,0x00,0x22,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x10,0x50,0x88,0x44,0x44,0x1C,0x52,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x10,0x41,0x08,0x44,0x44,0xE0,0x8A,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0xF0,0x41,0x08,0x7F,0xFC,0x43,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x10,0x42,0x08,0x40,0x04,0x00,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//////////////////////////////////////////////
/////////// 延时函数 ////////////////
////////////////////////////////////////////
void delay(uint m)
{
uint i=0;
while(i<m)
{
i++;
}
}
void Delay10ms() //@12.000MHz//延时10毫秒
{
unsigned char i, j;
_nop_();
_nop_();
i=117;
j=183;
do
{
while (--j);
}
while (--i);
}
//////////////////////////////////////////////
/////////// 初始化函数 ////////////////
////////////////////////////////////////////
void Iint_Parameter(void)
{
P1ASF=0X01; //设置P1.0口为模拟量输入口
ADC_RES=0; //单片机AD采集寄存器清零
ADC_CONTR=ADC_POWER|ADC_SPEEDLL|ADC_START; //启动AD
Delay10ms();
EA=1; //开中断
SI=0;
CLK=0;
}
void busy() //检测液晶屏忙状态
{
uchar i=255;
P0=0XFF;
RS=0; //设置该字节数据为命令代码
RW=1; //设置此次操作为读
E=1; //使能
while((i--)&&(P0&0X80)); //等待液晶屏不忙
E=0;
}
void Write12864(uchar Dat,bit command)
{
busy();
P0=Dat; //将命令写入总线
RS=command;
RW=0;
_nop_(); //空操作,做短暂的延时
E=1; //E的下降沿,数据写入
_nop_(); //空操作,做短暂的延时
E=0; //E的下降沿,数据写入
}
void WrGdram12864(uchar x,uchar y,uchar *map,uchar high,uchar wide)
{
uchar line,row;
Write12864(0x36,0); //液晶屏图形显示方式设置
if(wide%8==0)
wide=wide/8;
else wide=wide/8+1;
for(line=0;line<high;line++)
{
if(x+line>31)
{
Write12864(0x80+x+line-32,0); //设置行首地址
Write12864(0x80+y+8,0); //设置列首地址
}
else {
Write12864(0x80+x+line,0); //设置行首地址
Write12864(0x80+y,0); //设置列首地址
}
for(row=0;row<wide;row++)
Write12864(map[line*wide+row],1); //写入图像数据
}
}
void ClrGdram12864()
{
uchar line,row;
Write12864(0x34,0);
for(line=0;line<32;line++)
{
Write12864(0x80+line,0); //写入行首地址
Write12864(0x80,0); //写入列首地址
for(row=0;row<32;row++)
Write12864(0,1); //给图形寄存器写入数据0
}
}
void init_lcd(void)
{
RST=0; //复位液晶
delay(1000); //加些延时
RST=1; //复位结束
delay(1000); //加些延时
PSB=1; //选择8bit并口
Write12864(0x38,0); //基本指令集
Delay10ms(); //延时10毫秒
Write12864(0x01,0); //清除显示(清零DDRAM)
Delay10ms(); //延时10毫秒
Write12864(0x0c,0); //显示开
Delay10ms(); //延时10毫秒
}
void StartIntegration()
{
uchar i=0;
SI=1;
delay(5);
CLK=1;
delay(5);
SI=0;
delay(5);
CLK=0;
for(i=0;i<127;i++)
{
delay(5);
CLK=1;
delay(5);
CLK=0;
}
delay(5);
CLK=1;
delay(5);
CLK=0;
delay(5);
}
|