|
做的是酒精傳感器
#include<pic.h>
//__CONFIG(0x3F3A);
//__CONFIG(0x1832);
__CONFIG(FOSC_HS & WDTE_OFF );
char cc1[]=" Alcohol Tester ";
#define RS RE0
#define RW RE1
#define EN RE2
#define LCD_BUS PORTD
#define BEEP RC2
unsigned int CMQ3=0;
unsigned char Vol=0;
unsigned int AlarmVol=20;
void delayms(unsigned int ms) //延時(shí)xx毫秒
{
unsigned char i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void command(unsigned int com) //LCD寫指令
{
RS=0; //RS為0
LCD_BUS=com; //裝載指令
delayms(2); //延時(shí)2ms
EN=1; //LCD使能
delayms(2); //延時(shí)2ms
EN=0; //LCD不使能
}
void write_dat(unsigned char dat) //LCD寫數(shù)據(jù)
{
RS=1; //RS為1
LCD_BUS=dat; //裝載數(shù)據(jù)
delayms(2); //延時(shí)2ms
EN=1; //LCD使能
delayms(2); //延時(shí)2ms
EN=0; //LCD不使能
}
void writestring(unsigned char x,unsigned char y,unsigned char *s) //LCD 寫字符串
{
if (y == 0) command(0x80 + x); //表示第一行
else command(0xC0 + x); //表示第二行
while (*s) //判斷是否字符串的結(jié)尾
{
write_dat( *s); //顯示當(dāng)前字符
s ++; //字符串地址加1
}
}
void writeChar(unsigned char x,unsigned char y,unsigned char s) //LCD 寫字符串
{
if (y == 0) command(0x80 + x); //表示第一行
else command(0xC0 + x); //表示第二行
{
write_dat( s); //顯示當(dāng)前字符
}
}
void LCD_Initial(void) //LCD初始化
{
EN=0; //LCD不使能
RW=0; //RW為0
command(0x38); //發(fā)送初始化指令
command(0x0c); //發(fā)送初始化指令
command(0x06); //發(fā)送初始化指令
command(0x01); //發(fā)送初始化指令
command(0x80); //發(fā)送LCD初始位置
}
interrupt ISR(void) //中斷子程序
{
if(ADIE && ADIF==1) //AD轉(zhuǎn)換中斷
{
ADIF=0; // A/D標(biāo)志位清零
Vol=ADRESH; // 高八位送PORTD
//GO_nDONE =1; // 啟動(dòng)下一次A/D轉(zhuǎn)換ADGO
}
}
void main(void)
{
unsigned char i=0;
unsigned int temp1=0;
float Dat=0;
TRISD=0x00;
TRISC=0X00;
TRISE=0x00;
ADCON1=0X0e;
TRISA=0x01;
ADCON0=0X01;
BEEP=1;
TRISB=0xff;
OPTION_REG&=0x7f;
ADCS1=1;
ADCS0=0; // A/D轉(zhuǎn)換時(shí)鐘32分頻
CHS2=0;
CHS1=0;
CHS0=0; // CHS2:CHS0=001, |
|