//程序头函数
#include
//显示函数
//宏定义
#define uint unsigned int
#define uchar unsigned char
#define Data_ADC0809 P1
//管脚声明
***it LED_yanwu= P2^1;
***it baojing= P2^5;
//ADC0809
***it ST=P3^3;
***it EOC=P3^6;
***it OE=P3^2;
//按键
***it Key1=P2^6;
***it Key2=P2^7;
***it Key3=P3^7;
signed char y; //浓度值全局变量
uint c; //浓度值全局变量
bit bdata flag=0;
//co含量变量
uchar nongdu;
uchar yushe_yanwu=45;
//按钮模式|
uchar Mode=0;
//函数声明
extern uchar ADC0809();
extern void Key();
void delay(uint z)
{
uint i,j;
for(i=0;i
for(j=0;j<121;j++);
}
//ADC0809读取信息
uchar ADC0809()
{
uchar yanwu_=0x00;
//转化初始化
ST=0;
//开始转换
ST=1;
ST=0;
//外部中断等待AD转换结束
while(EOC==0)
//读取转换的AD值
OE=1;
yanwu_=Data_ADC0809;
OE=0;
return yanwu_;
}
void Key()
{ //模式选择
if(Key1==0)
{
while(Key1==0);
if(Mode>=3) Mode=0;
else
{
}
}
if(Key2==0&&Mode!=0)
{
while(Key2==0);
switch(Mode)
{
case 1:
{
yushe_yanwu++;
if(yushe_yanwu>=255)
yushe_yanwu=255;
write_com(0x80+13);
write_data(0x30+yushe_yanwu/100);
write_data(0x30+yushe_yanwu%100/10);
write_data(0x30+yushe_yanwu%10);
break;
}
}
}
if(Key3==0&&Mode!=0)
{
while(Key3==0);
switch(Mode)
{
case 1:
{
yushe_yanwu--;
if(yushe_yanwu<=0)
yushe_yanwu=0;
write_data(0x30+yushe_yanwu%100/10);
write_data(0x30+yushe_yanwu%10);
break;
}
}
}
delay(200);
}
/*****************************************************************
iic控制1602 lcd
*****************************************************************/
#include
#include
#define uchar unsigned char
#define uint unsigned int
***it SCL = P1^5;
***it SDA = P1^6;
char ADDR = 0x7E;
void delay(int ms);
void IIC_start(void);
void IIC_stop(void);
void IIC_writeByte(char temp);
void send_command(char comm);
void send_data(char data1);
void init_lcd(void);
void clear_lcd(void);
void print_lcd(int x, int y, char *str);
void print_customer(int x, int y, char str[]);
void main(){
unsigned char table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00}; //×?·???
unsigned char table1[]={
0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E,
0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,
0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,
0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00
};//????°?
init_lcd();
print_lcd(0,0,"Hello! >_<");
print_lcd(0,1," I Love U -Gao W");
//print_customer(0,0,table);
while(1);
}
void delay(int ms){
unsigned char y ;
while(ms--){
for(y = 0 ; y<250 ; y++){
_nop_() ;
_nop_() ;
_nop_() ;
_nop_() ;
}
}
}
void IIC_start(void){
SDA=1;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
}
//????????
void IIC_stop(void){
SDA=0;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
_nop_();
_nop_();
}
void IIC_writeByte(char temp){
char i;
for(i=0;i<8;i++){
SDA=(bit)(temp & 0x80) ;
temp <<=1;
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
}
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
while(SDA);
_nop_();
SCL=0;
}
void send_command(char comm){
char tmp;
IIC_start();
IIC_writeByte(ADDR);
tmp = comm & 0xF0;
tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB; //Make EN = 0
IIC_writeByte(tmp);
tmp = (comm & 0x0F) << 4 ;
tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB; // Make EN = 0
IIC_writeByte(tmp);
//stop_8574();
}
void send_data(char data1){
char tmp;
IIC_start();
IIC_writeByte(ADDR);
tmp = data1 & 0xF0;
tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB; //Make EN = 0
IIC_writeByte(tmp);
tmp = (data1 & 0x0F) << 4 ;
tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB ; // Make EN = 0
IIC_writeByte(tmp);
}
//LCD????"?
void init_lcd(void){
send_command(0x33);
delay(50) ;
send_command(0x32);
delay(50) ;
send_command(0x28);
delay(50) ;
send_command(0x0C);
delay(50) ;
send_command(0x06);
delay(50) ;
send_command(0x01);
delay(50) ;
}
//Clear Screen
void clear_lcd(void){
send_command(0x01);
}
void print_lcd(int x, int y, char *str){
char addr;
if( x < 0){
x = 0;
}
if(x > 15){
x = 15;
}
if(y<0){
y = 0;
}
if(y > 1){
y = 1;
}
// Move cursor
addr = 0x80 + 0x40 * y + x;
send_command(addr);
while (*str) {
send_data(*str++);
}
}
void print_customer(int x, int y, char *str){
unsigned char i,tmp;
for(i=0;i<8;i++){
send_command(0x40+i);
send_data(*str++);
}
}
/****************************************************
结束
****************************************************/
void main()
{
check_nongdu();
check_nongdu();
Init_lcd();
while(1)
{
yanwu=ADC0809();
check_nongdu();
Key();
if(Mode==0)
{
Display_lcd(yushe_yanwu,c,nongdu);
if(nongdu>=yushe_yanwu)
{
LED_yanwu=0;
baojing=0;
}
else
{
LED_yanwu=1;
}
if((nongdu
{
baojing=1;
}
}
}
}
|