1602 AVR單片機版 報警指示功能
void delay_1ms(); //延時1毫秒
void delay_nms(uint n); //延時n毫秒
void wait(); //繁忙等待函數(shù)
void writedata(uchar w); //寫數(shù)據(jù)
void writecmd(uchar cmd); //寫指令
void init(); //1602初始化
void display(uchar x,uchar y,uchar *P); //顯示字符串函數(shù)
void delay(uint k) //常用延遲函數(shù)
{
uint i,j;
for(i=0;i
for(j=0;j<1140;j++);
}
void main()
{
DDRB=0xff; //設(shè)置PB口為輸出
PORTB=0xff;
DDRD=0x00; //中斷源設(shè)置為輸入
PORTD=0xff;
MCUCR=0x02; //中斷為下降沿
GICR=0xc0; //中斷為int0,int1
SREG=0x80; //中斷總開關(guān)
init();
while(1)
{
PORTB=0xff;
delay(300);
PORTB=0x00;
delay(300);
display(5,0,normal);
display(3,1,indication);
}
}
#pragma vector = 0x04
__interrupt void qq() //中斷產(chǎn)生報警
{
writecmd(0x01); //清屏
while(1)
{
display(6,0,alarm);
PORTB=0x00;
}
}
//-----------------------庫函數(shù)------------------------
void wait()
{
uchar val;
DATAPORT=0xff;
RS0;
RW1;
__no_operation();
EN1;
__no_operation(); //注:一個__no_operation();延時130ns;
__no_operation();
DDRA=0x00;
val=PINA;
while(val&busy)val=PINA;
EN0;
DDRA=0xff;
}
void writecmd(uchar w)
{
wait();
RS0;
RW0;
__no_operation();
DATAPORT=w;
__no_operation();
EN1;
__no_operation();
__no_operation();
EN0;
}
void writedata(uchar data)
{
wait();
RS1;
RW0;
__no_operation();
DATAPORT=data;
__no_operation();
EN1;
__no_operation();
__no_operation();
EN0;
}
void delay_nms(uint k)
{
uint i,j;
for(i=0;i
for(j=0;j<1140;j++);
}
void init()
{
delay_nms(15);
writecmd(0x38);
delay_nms(5);
writecmd(0x38);
delay_nms(5);
writecmd(0x38);
writecmd(0x80);
writecmd(0x01);
writecmd(0x06);
writecmd(0x0c);
}
void display(uchar x,uchar y,uchar *p)
{
uchar add=0x80; //1602數(shù)據(jù)指針初值
y=y&0x01;
x=x&0x0f;
if(y)add=add+0x40; //顯示第二行加數(shù)據(jù)指針加0x40
writecmd(add+x);
while(*p!=