新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 1602 AVR單片機版 報警指示功能

        1602 AVR單片機版 報警指示功能

        作者: 時間:2016-11-30 來源:網絡 收藏

        void delay_1ms(); //延時1毫秒
        void delay_nms(uint n); //延時n毫秒
        void wait(); //繁忙等待函數
        void writedata(uchar w); //寫數據
        void writecmd(uchar cmd); //寫指令
        void init(); //1602初始化
        void display(uchar x,uchar y,uchar *P); //顯示字符串函數


        void delay(uint k) //常用延遲函數
        {
        uint i,j;
        for(i=0;i
        for(j=0;j<1140;j++);
        }

        void main()
        {
        DDRB=0xff; //設置PB口為輸出
        PORTB=0xff;
        DDRD=0x00; //中斷源設置為輸入
        PORTD=0xff;
        MCUCR=0x02; //中斷為下降沿
        GICR=0xc0; //中斷為int0,int1
        SREG=0x80; //中斷總開關
        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() //中斷產生報警
        {
        writecmd(0x01); //清屏
        while(1)
        {
        display(6,0,alarm);
        PORTB=0x00;
        }
        }
        //-----------------------庫函數------------------------
        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數據指針初值
        y=y&0x01;
        x=x&0x0f;
        if(y)add=add+0x40; //顯示第二行加數據指針加0x40
        writecmd(add+x);
        while(*p!= 主站蜘蛛池模板: 林甸县| 灌云县| 莎车县| 闻喜县| 海原县| 毕节市| 库尔勒市| 常德市| 武穴市| 福安市| 宁强县| 上虞市| 亳州市| 桐柏县| 武宁县| 当阳市| 南昌市| 交城县| 迁西县| 汉中市| 徐闻县| 阳谷县| 兰西县| 高雄市| 海口市| 绥化市| 固原市| 浦城县| 峨山| 静安区| 八宿县| 余姚市| 江门市| 通道| 介休市| 日照市| 和平县| 临泽县| 遂昌县| 武穴市| 禹州市|