|
做的是酒精传感器
#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) //延时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); //延时2ms
EN=1; //LCD使能
delayms(2); //延时2ms
EN=0; //LCD不使能
}
void write_dat(unsigned char dat) //LCD写数据
{
RS=1; //RS为1
LCD_BUS=dat; //装载数据
delayms(2); //延时2ms
EN=1; //LCD使能
delayms(2); //延时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) //判断是否字符串的结尾
{
write_dat( *s); //显示当前字符
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); //显示当前字符
}
}
void LCD_Initial(void) //LCD初始化
{
EN=0; //LCD不使能
RW=0; //RW为0
command(0x38); //发送初始化指令
command(0x0c); //发送初始化指令
command(0x06); //发送初始化指令
command(0x01); //发送初始化指令
command(0x80); //发送LCD初始位置
}
interrupt ISR(void) //中断子程序
{
if(ADIE && ADIF==1) //AD转换中断
{
ADIF=0; // A/D标志位清零
Vol=ADRESH; // 高八位送PORTD
//GO_nDONE =1; // 启动下一次A/D转换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转换时钟32分频
CHS2=0;
CHS1=0;
CHS0=0; // CHS2:CHS0=001, |
|