粗大浓稠硕大噗嗤噗嗤h,精品人妻码一区二区三区,国产av无码专区亚洲精品,日韩a片无码毛片免费看小说

PLC企業(yè)資訊
    萬代觸摸芯片8051與WTC6312BSI 6316BSI接口程序范例
    發(fā)布者:oweis88  發(fā)布時(shí)間:2015-09-01 10:14:33

    萬代觸摸芯片8051與WTC6312BSI 6316BSI接口程序范例

    萬代觸摸芯片WTC6312BSI程序

    萬代觸摸芯片WTC6316BSI程序

    1 多鍵組合(SHIFT)工作模式的操作程序范例
    該范例程序?qū)崿F(xiàn)的功能是8051 從觸摸芯片的SPI 口讀取按鍵信息,并用
    LED加以顯示。每一個(gè)LED顯示一個(gè)相應(yīng)按鍵的狀態(tài)。并給出了通過SPI口設(shè)
    置觸摸芯片的靈敏度的功能函數(shù)。
    #include <reg51.h>
    #define uchar unsigned char
    #define uint unsigned int
    //--------------------------------WTC6316BSI SPI接口---------------------------------------------
    sbit SCS = P1^3;
    sbit SCK = P1^2;
    sbit SDO = P1^1;
    sbit SDI = P1^0;
    //--------------------------------LED 顯示界面---------------------------------------------
    sbit LED15 = P2^7;
    sbit LED14 = P2^6;
    sbit LED13 = P2^5;
    sbit LED12 = P2^4;
    sbit LED11 = P2^3;
    sbit LED10 = P2^2;
    sbit LED9 = P2^1;
    sbit LED8 = P2^0;
    sbit LED7 = P0^7;
    sbit LED6 = P0^6;
    sbit LED5 = P0^5;
    sbit LED4 = P0^4;
    sbit LED3 = P0^3;
    sbit LED2 = P0^2;
    sbit LED1 = P0^1;
    sbit LED0 = P0^0;
    //------------------------------------the funtion define-------------------------------------
    void delay_loop(uint i);
    void set_Subtle_SPI(uchar temp); //用軟件設(shè)置WTC6316BSI靈敏度
    uchar get_key_data(void); //讀取WTC6316BSI SPI接口數(shù)據(jù)
    void shift_led_disp(void); //用LED 顯示按鍵狀態(tài)//------------------------------------the register define -----------------------------------
    uchar GetKey; //從SPI口讀到的數(shù)值
    uchar SwitchImage[3]; //觸摸按鍵狀態(tài)寄存器
    //------------------------------------------------------------------------------------------
    void main(void)
    {
    init();
    SCS = 1; //關(guān)閉SPI口使能
    SCK = 1; //SCK 初始電平為高
    SDI = 1; //SDI設(shè)置為高電平
    while(1)
    {
    delay_loop(400); //延時(shí),實(shí)際程序中可以每4MS讀一次SPI口
    SDI = 1;
    GetKey = get_key_data(); //讀取SPI接口的數(shù)據(jù)
    if((GetKey & 0x03)== 0) //檢測低2位的幀信息識(shí)別位
    { //第一幀
    SwitchImage[0] = GetKey;
    shift_led_disp(); //用LED 顯示讀取的按鍵狀態(tài)
    }
    else if((GetKey & 0x03)== 1) //檢測低2位的幀信息識(shí)別位
    { //第二幀
    SwitchImage[1] = GetKey;
    shift_led_disp(); //用LED 顯示讀取的按鍵狀態(tài)
    }
    else if((GetKey & 0x03)== 2) //檢測低2位的幀信息識(shí)別位
    { //第三幀
    SwitchImage[2] = GetKey;
    shift_led_disp(); //用LED 顯示讀取的按鍵狀態(tài)
    }
    }
    }
    //------------------------------------------------------------------------------------------
    void shift_led_disp(void)
    {
    if((SwitchImage[2] & 0x20) != 0) {LED15 = 0;} //點(diǎn)亮LED
    else {LED15 = 1;} //熄滅LEDif((SwitchImage[2] & 0x10) != 0) {LED14 = 0;}
    else {LED14 = 1;}
    if((SwitchImage[2] & 0x08) != 0) {LED13 = 0;}
    else {LED13 = 1;}
    if((SwitchImage[2] & 0x04) != 0) {LED12 = 0;}
    else {LED12 = 1;}
    if((SwitchImage[1] & 0x80) != 0) {LED11 = 0;} //點(diǎn)亮LED
    else {LED11 = 1;} //熄滅LED
    if((SwitchImage[1] & 0x40) != 0) {LED10 = 0;}
    else {LED10 = 1;}
    if((SwitchImage[1] & 0x20) != 0) {LED9 = 0;}
    else {LED9 = 1;}
    if((SwitchImage[1] & 0x10) != 0) {LED8 = 0;}
    else {LED8 = 1;}
    if((SwitchImage[1] & 0x08) != 0) {LED7 = 0;}
    else {LED7 = 1;}
    if((SwitchImage[1] & 0x04) != 0) {LED6 = 0;}
    else {LED6 = 1;}
    if((SwitchImage[0] & 0x80) != 0) {LED5 = 0;}
    else {LED5 = 1;}
    if((SwitchImage[0] & 0x40) != 0) {LED4 = 0;}
    else {LED4 = 1;}
    if((SwitchImage[0] & 0x20) != 0) {LED3 = 0;}
    else {LED3 = 1;}
    if((SwitchImage[0] & 0x10) != 0) {LED2 = 0;}
    else {LED2 = 1;}
    if((SwitchImage[0] & 0x08) != 0) {LED1 = 0;}
    else {LED1 = 1;}
    if((SwitchImage[0] & 0x04) != 0) {LED0 = 0;}
    else {LED0 = 1;}
    }
    //------------------------------------------------------------------------------------------
    uchar get_key_data(void)
    {
    uchar KeyData;
    uchar i;
    KeyData = 0;
    i = 0; //計(jì)數(shù)器指初始為0SDI = 1; //SDI置為高,以避免錯(cuò)誤設(shè)置觸摸芯片的靈敏度
    SCS = 0; //打開SPI口使能
    do
    {
    KeyData <<= 1; //MSB為數(shù)據(jù)第一位
    SCK = 0; //SCK 信號(hào)下降沿
    SCK = 1; //SCK 信號(hào)上升沿
    if(SDO == 1) //讀取SDO的數(shù)據(jù)
    { //SDI為高電平
    KeyData |= 0x01;
    }
    else
    { //SDI為低電平
    KeyData &= 0xFE;
    }
    i++; //計(jì)數(shù)器加1
    }while (i < 8); //循環(huán)讀數(shù)8次
    SCS = 1; //關(guān)閉SPI口使能
    return(KeyData); //返回讀取的按鍵信息
    }
    //------------------------------------------------------------------------------------------
    void set_Subtle_SPI(uchar temp)
    {
    uchar i;
    i= 0; //計(jì)數(shù)器指初始為0
    SCS = 0; //打開SPI口使能
    do
    {
    if((temp & 0x80) != 0) //發(fā)送數(shù)據(jù)的第一位為MSB
    { //敏感度設(shè)定值的當(dāng)前位值為1
    SDI = 1;
    }
    else
    { //敏感度設(shè)定值的當(dāng)前位值為0
    SDI = 0;
    }
    SCK = 0; //SCK 信號(hào)下降沿
    SCK = 1; //SCK 信號(hào)上升沿temp <<= 1; //發(fā)送數(shù)據(jù)的第一位為MSB
    i++; //計(jì)數(shù)器加1
    }while (i < 8); //循環(huán)發(fā)送8次
    SCS = 1; //關(guān)閉SPI口使能
    SDI = 1; //SDI設(shè)置為高電平
    }
    //------------------------------------------------------------------------------------------
    void delay_loop(uint i)
    {
    while(i > 0)
    {
    i--;
    }
    }
    2 8051 與WTC6316BSI 接口的單鍵工作模式的操作程序范例
    該范例程序?qū)崿F(xiàn)的功能是8051 從觸摸芯片的SPI 口讀取按鍵信息,并用
    LED加以顯示。每一個(gè)LED顯示一個(gè)相應(yīng)按鍵的狀態(tài)。并給出了通過SPI口設(shè)
    置觸摸芯片的靈敏度的功能函數(shù)
    #include <reg51.h>
    #define uchar unsigned char
    #define uint unsigned int
    //--------------------------------WTC6316BSI SPI接口---------------------------------------------
    sbit SCS = P1^3;
    sbit SCK = P1^2;
    sbit SDO = P1^1;
    sbit SDI = P1^0;
    //--------------------------------LED 顯示界面---------------------------------------------
    sbit LED15 = P2^7;
    sbit LED14 = P2^6;
    sbit LED13 = P2^5;
    sbit LED12 = P2^4;
    sbit LED11 = P2^3;
    sbit LED10 = P2^2;
    sbit LED9 = P2^1;
    sbit LED8 = P2^0;sbit LED7 = P0^7;
    sbit LED6 = P0^6;
    sbit LED5 = P0^5;
    sbit LED4 = P0^4;
    sbit LED3 = P0^3;
    sbit LED2 = P0^2;
    sbit LED1 = P0^1;
    sbit LED0 = P0^0;
    //------------------------------------功能函數(shù)-------------------------------------
    void delay_loop(uchar i); //延時(shí)函數(shù)
    void led_on(uchar LedControler); //開LED
    void led_off(); //關(guān)LED
    void set_Subtle(uchar subtle); //設(shè)置WTC6316BSI的敏感度
    uchar get_keyValue(void); //讀取觸摸按鍵狀態(tài)
    //------------------------------------變量定義 -----------------------------------
    uchar GetKey; //從WTC6316BSI讀取的按鍵值
    //GetKey == 0xFF 表示沒有按鍵觸摸或按鍵已經(jīng)彈開
    //GetKey 不等于 0xFF 表示有按鍵正在被觸摸
    //------------------------------------------------------------------------------------------
    //
    //------------------------------------------------------------------------------------------
    void main(void)
    {
    SCS = 1; //關(guān)閉SPI口使能
    SCK = 1; //SCK 初始電平為高
    SDI = 1; //SDI設(shè)置為高電平
    set_Subtle(10); //將WTC6316BSI的敏感度初始化為10
    while(1)
    {
    delay_loop(500); //延時(shí),實(shí)際程序中可以每4MS讀一次SPI口
    GetKey = get_keyValue(); //讀取按鍵信息
    if(GetKey != 0xFF)
    { //有鍵按下點(diǎn)亮相應(yīng)鍵的指示LED
    led_on(GetKey);
    }
    else
    { //沒有按鍵按下或鍵彈開,關(guān)閉所有指示LED
    led_off();}
    }
    }
    //------------------------------------------------------------------------------------------
    uchar get_keyValue(void)
    {
    uchar KeyValue;
    uchar i;
    i = 0; //計(jì)數(shù)器指初始為0
    SDI = 1; //SDI置為高,以避免錯(cuò)誤設(shè)置觸摸芯片的靈敏度
    SCS = 0; //打開SPI口使能
    do
    {
    KeyValue <<= 1; //MSB為數(shù)據(jù)第一位
    SCK = 0; //SCK 信號(hào)下降沿
    SCK = 1; //SCK 信號(hào)上升沿
    if(SDO == 1) //讀取SDO的數(shù)據(jù)
    { //SDI為高電平
    KeyValue |= 0x01;
    }
    else
    { //SDI為低電平
    KeyValue &= 0xFE;
    }
    i++; //計(jì)數(shù)器加1
    }while (i < 8); //循環(huán)讀數(shù)8次
    SCS = 1; //關(guān)閉SPI口使能
    return(KeyValue); //返回讀取的按鍵信息
    }
    //------------------------------------------------------------------------------------------
    void set_Subtle(uchar subtle)
    {
    uchar i;
    i= 0; //計(jì)數(shù)器指初始為0
    SCS = 0; //打開SPI口使能
    do
    {
    if((temp & 0x80) != 0) //發(fā)送數(shù)據(jù)的第一位為MSB
    { //敏感度設(shè)定值的當(dāng)前位值為1SDI = 1;
    }
    else
    { //敏感度設(shè)定值的當(dāng)前位值為0
    SDI = 0;
    }
    SCK = 0; //SCK 信號(hào)下降沿
    SCK = 1; //SCK 信號(hào)上升沿
    temp <<= 1; //發(fā)送數(shù)據(jù)的第一位為MSB
    i++; //計(jì)數(shù)器加1
    }while (i < 8); //循環(huán)發(fā)送8次
    SCS = 1; //關(guān)閉SPI口使能
    SDI = 1; //SDI設(shè)置為高電平
    }
    //-----------------------------------------------------------------------------------------
    void delay_loop(uint i)
    {
    while(i)
    {
    i--;
    }
    }
    //------------------------------------------------------------------------------------------
    void led_on(uchar LedControler)
    {
    switch(LedControler)
    {
    case 0: LED0 = 0; break;
    case 1: LED1 = 0; break;
    case 2: LED2 = 0; break;
    case 3: LED3 = 0; break;
    case 4: LED4 = 0; break;
    case 5: LED5 = 0; break;
    case 6: LED6 = 0; break;
    case 7: LED7 = 0; break;
    case 8: LED8 = 0; break;
    case 9: LED9 = 0; break;
    case 10: LED10 = 0; break;case 11: LED11 = 0; break;
    case 12: LED12 = 0; break;
    case 13: LED13 = 0; break;
    case 14: LED14 = 0; break;
    case 15: LED15 = 0; break;
    }
    }
    //------------------------------------------------------------------------------------------
    void led_off (void)
    {
    LED0 = 1;
    LED1 = 1;
    LED2 = 1;
    LED3 = 1;
    LED4 = 1;
    LED5 = 1;
    LED6 = 1;
    LED7 = 1;
    LED8 = 1;
    LED9 = 1;
    LED10 = 1;
    LED11 = 1;
    LED12 = 1;
    LED13 = 1;
    LED14 = 1;
    LED15 = 1;
    }

     

    版權(quán)聲明PLC信息網(wǎng)轉(zhuǎn)載作品均注明出處,本網(wǎng)未注明出處和轉(zhuǎn)載的,是出于傳遞更多信息之目的,并不意味 著贊同其觀點(diǎn)或證實(shí)其內(nèi)容的真實(shí)性。如轉(zhuǎn)載作品侵犯作者署名權(quán),或有其他諸如版權(quán)、肖像權(quán)、知識(shí)產(chǎn)權(quán)等方面的傷害,并非本網(wǎng)故意為之,在接到相關(guān)權(quán)利人通知后將立即加以更正。聯(lián)系電話:0571-87774297。
0571-87774297  
大肉大捧一进一出好爽视频| 含紧一点h边做边走动| 成人毛片A级毛片免费观看网站| 东京热网站| 天天摸夜夜摸夜夜狠狠摸| 久久久亚洲欧洲日产国码aⅴ| 男人又粗又大女人舒服吗| 草草地址线路①屁屁影院成人| 亚洲午夜久久久久妓女影院| 特级毛片a片久久久久久| 亚洲日韩精品一区二区三区| 婷婷伊人久久大香线蕉av| 亚洲欧美精品SUV| 亚洲av无码一区东京热| 欧美一极xxxxx| 人妻夜夜添夜夜无码av茄子视频| 中文无码亚洲精品字幕| 四虎永久在线精品无码| 久久伊人五月丁香狠狠色| av无码免费一区二区三区| 一本大道伊人av久久综合| 蜜臀AV性久久久久蜜臀AⅤ| 精品高朝久久久久9999| 97无码精品人妻一区二区| 久久精品一区二区三区四区| 偷玩朋友熟睡人妻| jrs直播(无插件)直播| 大又大粗又爽又黄少妇毛片| 漂亮人妻洗澡被公强| 无码少妇精品一区二区免费动态| 成人精品一区二区三区电影| 久久亚洲av成人无码国产电影| 国产香港明星裸体xxxx视频| 我和黑帮老大的365天| 欧美大黑bbbbbbbbb| 亚洲av在线观看| 夫妻那些事全集免费观看电视剧| 国产99久久久久久免费看| 久久精品人妻一区二区蜜桃| 亚洲国产成人片在线观看无码| https日韩在线 | 中文) |