新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > stm32之模擬i2c驅動ht16c22

        stm32之模擬i2c驅動ht16c22

        作者: 時間:2016-12-03 來源:網絡 收藏
        iic.h文件如下:

        #ifndef _stm32f103_myi2c_h_
        #define _stm32f103_myi2c_h_

        //IO方向設置
        #define SDA_IN() {GPIOB->CRH&=0XFFFF0FFF;GPIOB->CRH|=8<<12;}
        #define SDA_OUT() {GPIOB->CRH&=0XFFFF0FFF;GPIOB->CRH|=3<<12;}

        //IO操作函數
        #define IIC_SCL PBout(10) //SCL
        #define IIC_SDA PBout(11) //SDA
        #define READ_SDA PBin(11) //輸入SDA


        //ht16c22內部 參數設置
        #define SlaveAddress 0x7e //0x7e

        #define ModeSet 0x8c //80Hz,turn on sys and LCD bias,1/3 bias

        #define VlcdAdjust 0x70 //0x7F --Vlcd=0.6VDD,Seg Pin,enable internal voltage

        #define Blink 0xC0 //關閉閃爍

        //IIC所有操作函數
        void IIC_Init(void); //初始化IIC的IO口
        void IIC_Start(void); //發送IIC開始信號
        void IIC_Stop(void); //發送IIC停止信號
        void IIC_Send_Byte(u8 txd); //IIC發送一個字節
        u8 IIC_Read_Byte(unsigned char ack);//IIC讀取一個字節
        u8 IIC_Wait_Ack(void); //IIC等待ACK信號
        void IIC_Ack(void); //IIC發送ACK信號
        void IIC_NAck(void); //IIC不發送ACK信號

        void IIC_Write_One_Byte(u8 daddr,u8 addr,u8 data);
        u8 IIC_Read_One_Byte(u8 daddr,u8 addr);
        void ht16c22_init(void);
        void ht16c22_display(unsigned char add,unsigned char dat);
        void ht16c22_test(void);
        unsigned char ht16c22_read(unsigned add);
        void ht16c22_dis_num(int num);
        void ht16c22_dis_staus(int num);
        void ht16c22_dis_bat(int num);
        void ht16c22_dis_month2(int num);

        /////////////////////////////////////////////////////////////////////////////////
        void status_digital(int num);//--------2
        void signal_digital(int num);//--------4
        void battery_digital(int num);//-------4
        void clock_digital(void);
        void first_digital(int num);//月1------2
        void first_digital_dismiss(void );//月份1不顯示
        void second_digital(int num);//月2----------10
        void second_digital_dismiss(void);//月份2不顯示
        void month_digital(void);
        void third_digital(int num);//day1----4
        void third_digital_dismiss(void );//day1 dismiss
        void fourth_digital(int num);//day2--------9
        //day2 dismiss
        void fourth_digital_dismiss(void );
        //hour1
        void fifth_digital(int num);//------3
        void fifth_digital_dismiss(void );//hour1 dismiss

        void sixth_digital(int num);//hour2--------9
        void sixth_digital_dismiss(void);//hour2 dismiss
        void mao_digital(void );
        //minute1 dismiss
        void seventh_digital_dismiss(void );
        //minute1
        void seventh_digital(int num);//---------6
        //minute2
        void eight_digital(int num);//-----------9
        void eight_digital_dismiss(void);//minute dismiss
        void nineth_digital(int num);//hum2-------9
        void nineth_o_digital(void );
        void nineth_dismiss_digital(void );

        //hum3
        void tenth_digital(int num);//--------9
        void tenth_digital_dismiss(void);
        void tenth_ON_digital(void);
        void the_on_off_digital(int num);//------2
        void tenth_OF_digital(void );
        //hum4
        void eleventh_digital(int num);//-------9
        void eleventh_digital_dismiss(void );
        //hum fuhao
        void temp_digital(int num);//--------9
        void dot_digital(int num);//-----2
        void minus_digital(void );
        void set_above_digital(int num);//---2
        void set_alarm_digital(int num);//----2
        void set_speaker_digital(int num);//----2
        //tem2
        void temp_high_digital(int num);//-------9
        void temp_high_digital_off(void );
        void temp_Middle_digital(int num);//tem3//---------9
        void temp_Middle_digital_off(void );
        //tem4
        void temp_Last_digital(int number);//--------9
        void temp_Last_digital_off(void );
        void dot_temp_digital(int num);//-----2
        void temp_digital_new(int num);//-----2
        void humid_digital_new(int num);//---2
        void addr_digital(int number);//----9
        void addr_digital_dismiss(void);
        void baud_digital(int num);//----9
        void baud_digital_dismiss(void);
        void temp_minus_digital(int num);//--------2
        void print_digital(int num);//---2
        void log_digital(int num);//--------2
        void erase_digital(int num);//--------2
        #endif

        本文引用地址:http://www.104case.com/article/201612/325191.htmiic.c文件內容為:

        /********************************copyright ythuitong by wit_yuan**************************/
        #include "bsp.h"

        //////////////////////////////////////////////////////////////////////////
        // 函數名 : IIC_Init
        // 功能 : 初始化i2c
        // 參數 : void
        // 作者 : wit_yuan
        // 時間 : 2014-11-07
        ////////////////////////////////////////////////////////////////////////////
        void IIC_Init(void)
        {
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD ; //推挽輸出
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_SetBits(GPIOB,GPIO_Pin_10|GPIO_Pin_11); //PB10,PB11 輸出高
        }
        //////////////////////////////////////////////////////////////////////////
        // 函數名 : IIC_Start
        // 功能 : i2c起始信號
        // 參數 : void
        // 作者 : wit_yuan
        // 時間 : 2014-11-07
        ////////////////////////////////////////////////////////////////////////////
        void IIC_Start(void)
        {
        SDA_OUT(); //sda線輸出
        IIC_SDA=1;
        IIC_SCL=1;
        Delay_us(4);
        IIC_SDA=0; //START:when CLK is high,DATA change form high to low
        Delay_us(4);
        IIC_SCL=0; //鉗住I2C總線,準備發送或接收數據
        }
        //////////////////////////////////////////////////////////////////////////
        // 函數名 : IIC_Stop
        // 功能 : i2c結束信號
        // 參數 : void
        // 作者 : wit_yuan
        // 時間 : 2014-11-07
        ////////////////////////////////////////////////////////////////////////////
        void IIC_Stop(void)
        {
        SDA_OUT();//sda線輸出
        IIC_SCL=0;
        IIC_SDA=0;//STOP:when CLK is high DATA change form low to high
        Delay_us(4);
        IIC_SCL=1;
        IIC_SDA=1;//發送I2C總線結束信號
        Delay_us(4);
        }
        //////////////////////////////////////////////////////////////////////////
        // 函數名 : IIC_Wait_Ack
        // 功能 : 等待i2c的應答信號
        // 參數 : void
        // 作者 : wit_yuan
        // 時間 : 2014-11-07
        ////////////////////////////////////////////////////////////////////////////
        //等待應答信號到來
        //返回值:1,接收應答失敗
        // 0,接收應答成功
        u8 IIC_Wait_Ack(void)
        {
        u8 ucErrTime=0;
        SDA_IN(); //SDA設置為輸入
        IIC_SDA=1;
        Delay_us(1);
        IIC_SCL=1;
        Delay_us(1);
        while(READ_SDA)
        {
        ucErrTime++;
        if(ucErrTime>250)
        {
        IIC_Stop();
        return 1;
        }
        }
        IIC_SCL=0;//時鐘輸出0
        return 0;
        }
        //////////////////////////////////////////////////////////////////////////
        // 函數名 : IIC_Ack
        // 功能 : 產生i2c的ack應答信號
        // 參數 : void
        // 作者 : wit_yuan
        // 時間 : 2014-11-07
        ////////////////////////////////////////////////////////////////////////////
        //產生ACK應答
        void IIC_Ack(void)
        {
        IIC_SCL=0;
        SDA_OUT();
        IIC_SDA=0;
        Delay_us(2);
        IIC_SCL=1;
        Delay_us(2);
        IIC_SCL=0;
        }
        //不產生ACK應答
        void IIC_NAck(void)
        {
        IIC_SCL=0;
        SDA_OUT();
        IIC_SDA=1;
        Delay_us(2);
        IIC_SCL=1;
        Delay_us(2);
        IIC_SCL=0;
        }
        //IIC發送一個字節
        //返回從機有無應答
        //1,有應答
        //0,無應答
        void IIC_Send_Byte(u8 txd)
        {
        u8 t;
        SDA_OUT();
        IIC_SCL=0;//拉低時鐘開始數據傳輸
        for(t=0;t<8;t++)
        {
        //IIC_SDA=(txd&0x80)>>7;
        if((txd&0x80)>>7)
        IIC_SDA=1;
        else
        IIC_SDA=0;
        txd<<=1;
        Delay_us(2);
        IIC_SCL=1;
        Delay_us(2);
        IIC_SCL=0;
        Delay_us(2);
        }
        }
        //讀1個字節,ack=1時,發送ACK,ack=0,發送nACK
        u8 IIC_Read_Byte(unsigned char ack)
        {
        unsigned char i,receive=0;
        SDA_IN();//SDA設置為輸入
        for(i=0;i<8;i++ )
        {
        IIC_SCL=0;
        Delay_us(2);
        IIC_SCL=1;
        receive<<=1;
        if(READ_SDA)receive++;
        Delay_us(1);
        }
        if (!ack)
        IIC_NAck();//發送nACK
        else
        IIC_Ack(); //發送ACK
        return receive;
        }

        void ht16c22_init(void)
        {
        IIC_Start();
        IIC_Send_Byte(SlaveAddress); // SlaveAddress 0x7e
        IIC_Wait_Ack();
        IIC_Send_Byte(ModeSet); // ModeSet 0x8C 80Hz,turn on sys and LCD bias,1/3 bias
        IIC_Wait_Ack();
        IIC_Send_Byte(Blink); // Blink 0xC0 //關閉閃爍
        IIC_Wait_Ack();
        IIC_Stop();
        }
        void ht16c22_display(unsigned char add,unsigned char dat)
        {
        IIC_Start();
        IIC_Send_Byte(SlaveAddress); // SlaveAddress 0x7e
        IIC_Wait_Ack();
        IIC_Send_Byte(add); // address
        IIC_Wait_Ack();
        IIC_Send_Byte(dat);
        IIC_Wait_Ack();
        IIC_Stop();
        }

        void ht16c22_test(void)
        {
        ht16c22_display(0x00,0xd7);
        ht16c22_display(0x01,0x00);
        ht16c22_display(0x02,0x00);
        ht16c22_display(0x03,0x00);
        ht16c22_display(0x04,0x00);
        ht16c22_display(0x05,0x00);
        ht16c22_display(0x06,0x00);
        ht16c22_display(0x07,0x00);
        ht16c22_display(0x08,0x00);
        ht16c22_display(0x09,0x00);
        ht16c22_display(0x0A,0x00);
        ht16c22_display(0x0B,0x00);
        ht16c22_display(0x0C,0x00);
        ht16c22_display(0x0D,0x00);
        ht16c22_display(0x0E,0x00);
        ht16c22_display(0x0F,0x00);
        ht16c22_display(0x10,0x00);
        ht16c22_display(0x11,0x00);
        ht16c22_display(0x12,0x00);
        ht16c22_display(0x13,0x00);
        ht16c22_display(0x14,0x00);
        ht16c22_display(0x15,0x00);

        }
        unsigned char ht16c22_read(unsigned add)
        {
        unsigned temp;
        IIC_Start();
        IIC_Send_Byte(SlaveAddress); // SlaveAddress 0x7e
        IIC_Wait_Ack();
        IIC_Send_Byte(add); // address
        IIC_Wait_Ack();
        IIC_Stop();
        IIC_Start();
        IIC_Send_Byte(SlaveAddress+1); // SlaveAddress 0x7e
        IIC_Wait_Ack();
        temp = IIC_Read_Byte(1);
        IIC_Stop();
        return temp;
        }

        void ht16c22_dis_num(int num)
        {
        switch(num)
        {
        case 0:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xd7);
        break;
        case 1:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0x06);
        break;
        case 2:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xe3);
        break;
        case 3:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xa7);
        break;
        case 4:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0x36);
        break;
        case 5:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xb5);
        break;
        case 6:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xf5);
        break;
        case 7:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0x07);
        break;
        case 8:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xf7);
        break;
        case 9:
        ht16c22_display(0x00,0x00);
        ht16c22_display(0x00,0xb7);
        break;
        default:


        break;
        }

        }
        //信號狀態與電池電量共用地址0x0c的8位,操作信號狀態需要先把電池電量保存。電池電量是高4位,信號狀態時低4位
        void ht16c22_dis_staus(int num)
        {

        int temp;
        temp = ht16c22_read(0x0c);
        ht16c22_display(0x0c,(~0x0f)&temp);
        switch(num)
        {
        case 0:
        ht16c22_display(0x0c,0x01 | temp);

        break;

        case 1:
        ht16c22_display(0x0c,0x03 | temp);
        break;

        case 2:
        ht16c22_display(0x0c,0x07 | temp);
        break;

        case 3:
        ht16c22_display(0x0c,0x0f | temp);
        break;
        default:
        break;

        }
        }


        void ht16c22_dis_bat(int num)
        {
        int temp;
        temp = ht16c22_read(0x0c);
        ht16c22_display(0x0c,(~0x70)&temp);
        switch(num)
        {
        case 0:
        ht16c22_display(0x0c,0x80 | temp);

        break;

        case 1:
        ht16c22_display(0x0c,0x90 | temp);
        break;

        case 2:
        ht16c22_display(0x0c,0xb0 | temp);
        break;

        case 3:
        ht16c22_display(0x0c,0xf0 | temp);
        break;
        default:
        break;
        }
        }

        //-------------月份十位顯示--------------
        // 0---不顯示 1---顯示
        //ht16c22 地址 0x0d

        //月份1不顯示
        void first_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x0d);
        ht16c22_display(0x0d,(~0x7f)&temp);

        }

        //月2不顯示
        void second_digital_dismiss(void)
        {
        int temp;
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,(~0x7f)&temp);
        }

        //day1

        //day1 dismiss
        void third_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x0f);
        ht16c22_display(0x0f,(~0x7f)&temp);
        }
        //day2

        //day2 dismiss
        void fourth_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x10);
        ht16c22_display(0x10,(~0x7f)&temp);
        }
        //hour1

        //hour1 dismiss
        void fifth_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x11);
        ht16c22_display(0x11,(~0x7f)&temp);
        }
        //hour2

        //hour2 dismiss
        void sixth_digital_dismiss(void)
        {
        int temp;
        temp = ht16c22_read(0x12);
        ht16c22_display(0x12,(~0x7f)&temp);
        }

        //minute1 dismiss
        void seventh_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x13);
        ht16c22_display(0x13,(~0x7f)&temp);
        }
        //minute

        //minute2 dismiss
        void eight_digital_dismiss(void)
        {
        int temp;
        temp = ht16c22_read(0x14);
        ht16c22_display(0x14,(~0x7f)&temp);
        }

        //hum2

        void nineth_o_digital(void )
        {
        int temp;
        temp = ht16c22_read(0x02);
        ht16c22_display(0x02,(~0xF7)&temp);
        temp = ht16c22_read(0x02);
        ht16c22_display(0x02,0xe4 | temp);
        }
        void nineth_dismiss_digital(void )
        {
        int temp;
        temp = ht16c22_read(0x02);
        ht16c22_display(0x02,(~0xF7)&temp);
        }
        //hum3
        void tenth_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xd7 | temp);
        break;

        case 1:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0x06 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xe3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xa7 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0x36 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xb5 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xf5 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0x17 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0xb7 | temp);
        break;
        }
        }
        void tenth_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0xF7)&temp);
        }
        void tenth_ON_digital(void )
        {
        int temp;
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0xF7)&temp);
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0x57 | temp);
        }



        void the_on_off_digital(int num)
        {
        int temp_o;
        int temp_n;
        temp_o = ht16c22_read(0x02);
        ht16c22_display(0x02,(~0xF7)&temp_o);
        temp_n = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0xF7)&temp_n);
        switch(num)
        {
        case 0:
        temp_o = ht16c22_read(0x02);
        ht16c22_display(0x02,( ~0xf7) & temp_o);
        temp_n = ht16c22_read(0x01);
        ht16c22_display(0x01,( ~0xf7) & temp_n);

        break;

        case 1:
        temp_o = ht16c22_read(0x02);
        ht16c22_display(0x02,0xe4 | temp_o);
        temp_n = ht16c22_read(0x01);
        ht16c22_display(0x01,0x57 | temp_n);
        break;

        case 2:
        temp_o = ht16c22_read(0x02);
        ht16c22_display(0x02,0xe4 | temp_o);
        temp_n = ht16c22_read(0x01);
        ht16c22_display(0x01,0x71 | temp_n);
        break;
        }

        }
        void tenth_OF_digital(void )
        {
        int temp;
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0xF7)&temp);
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0x71 | temp);
        }
        //hum4
        void eleventh_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xd7 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0x06 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xe3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xa7 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0x36 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xb5 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xf5 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0x17 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0xb7 | temp);
        break;
        }
        }
        void eleventh_digital_dismiss(void )
        {
        int temp;
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,(~0xF7)&temp);
        }
        //hum fuhao
        void temp_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x02);
        ht16c22_display(0x02,(~0x08)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x02);
        ht16c22_display(0x02,(~0x08) & temp);

        break;

        case 1:
        temp = ht16c22_read(0x02);
        ht16c22_display(0x02,0x08 | temp);
        break;
        }
        }

        void dot_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0x08)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,(~0x08) & temp);

        break;

        case 1:
        temp = ht16c22_read(0x01);
        ht16c22_display(0x01,0x08 | temp);
        break;
        }
        }
        void minus_digital()
        {
        int temp;
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,(~0x08)&temp);
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0x08 | temp);
        }
        void set_above_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,0x80 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,0x80 | temp);
        break;
        }
        }
        void set_low_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,0x80 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x0e);
        ht16c22_display(0x0e,0x80 | temp);
        break;
        }
        }

        void set_alarm_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x0f);
        ht16c22_display(0x0f,(~0x80)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x0f);
        ht16c22_display(0x0f,(~0x80)&temp);

        break;

        case 1:
        temp = ht16c22_read(0x0f);
        ht16c22_display(0x0f,0x80 | temp);
        break;
        }
        }

        //tem2
        void temp_high_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xf5 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0x60 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xd3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xf2 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0x66 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xb6 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xb7 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xe4 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,0xf6 | temp);
        break;
        }
        }
        void temp_high_digital_off(void )
        {
        int temp;
        temp = ht16c22_read(0x07);
        ht16c22_display(0x07,(~0xF7)&temp);
        }
        //tem3
        void temp_Middle_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xf5 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0x60 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xd3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xf2 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0x66 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xb6 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xb7 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xe0 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0xf6 | temp);
        break;
        }
        }

        void temp_Middle_digital_off(void )
        {
        int temp;
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,(~0xF7)&temp);
        }
        //tem4
        void temp_Last_digital(int number)
        {
        int temp;
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,(~0xF7)&temp);
        switch(number)
        {
        case 0:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xf5 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0x60 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xd3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xf2 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0x66 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xb6 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xb7 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xe0 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0xf6 | temp);
        break;
        }
        }

        void temp_Last_digital_off(void )
        {
        int temp;
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,(~0xF7)&temp);
        }
        void dot_temp_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,(~0x08)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,(~0x08)& temp);

        break;

        case 1:
        temp = ht16c22_read(0x08);
        ht16c22_display(0x08,0x08 | temp);
        break;
        }
        }

        void temp_digital_new(int num)
        {
        int temp;
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,(~0x08)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,(~0x08) & temp);

        break;
        case 1:
        temp = ht16c22_read(0x09);
        ht16c22_display(0x09,0x08 | temp);
        break;
        }
        }

        void humid_digital_new(int num)
        {
        int temp;
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,(~0x08)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,(~0x08) & temp);

        break;

        case 1:
        temp = ht16c22_read(0x00);
        ht16c22_display(0x00,0x08 | temp);
        break;
        }
        }
        void addr_digital(int number)
        {
        int temp;
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,(~0xF7)&temp);
        switch(number)
        {
        case 0:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xf5 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0x60 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xd3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xf2 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0x66 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xb6 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xb7 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xe0 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xf6 | temp);
        break;
        case 10:
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,0xe7 | temp);
        break;
        }
        }


        void addr_digital_dismiss(void)
        {
        int temp;
        temp = ht16c22_read(0x05);
        ht16c22_display(0x05,(~0xF7)&temp);
        }


        void baud_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xd7 | temp);

        break;

        case 1:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0x06 | temp);
        break;

        case 2:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xe3 | temp);
        break;

        case 3:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xa7 | temp);
        break;

        case 4:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0x36 | temp);

        break;

        case 5:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xb5 | temp);
        break;

        case 6:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xf5 | temp);
        break;

        case 7:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0x17 | temp);
        break;

        case 8:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xf7 | temp);
        break;

        case 9:
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,0xb7 | temp);
        break;
        }
        }
        void baud_digital_dismiss(void)
        {
        int temp;
        temp = ht16c22_read(0x04);
        ht16c22_display(0x04,(~0xF7)&temp);
        }

        void temp_minus_digital(int num)
        {
        int temp;
        temp = ht16c22_read(0x06);
        ht16c22_display(0x06,(~0xF7)&temp);
        switch(num)
        {
        case 0:
        temp = ht16c22_read(0x06);
        ht16c22_display(0x06,(~0xF7)& temp);

        break;

        case 1:
        temp = ht16c22_read(0x06);
        ht16c22_display(0x06,0x02| temp);
        break;
        }
        }


        /************************************end of file 2014-11-07*********************************/

        好了,不解釋了,這也是華麗的結束了。


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 房山区| 收藏| 会泽县| 绥化市| 潮安县| 金湖县| 安龙县| 福建省| 松桃| 胶州市| 永顺县| 民勤县| 如皋市| 青川县| 巴中市| 望谟县| 乐至县| 西峡县| 清原| 长阳| 康马县| 津市市| 信丰县| 涞水县| 紫云| 汝南县| 西乌珠穆沁旗| 新宁县| 宁陵县| 巴彦县| 芦山县| 乐亭县| 和平县| 台湾省| 胶州市| 北流市| 五台县| 东至县| 樟树市| 石阡县| 会宁县|