中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > ATmega16與觸摸屏的連接

        ATmega16與觸摸屏的連接

        作者: 時間:2017-06-04 來源:網絡 收藏
        是四線電阻式的,驅動芯片采用了很常見的ADS7846。ADS7846的典型應用電路圖如下圖所示。


        在筆者的應用中,pin7和pin8都直接連接到GND,即不使用輔助輸入通道,pin9和pin10連接在一起,即使用了VCC做為ADS7846的模數轉換參考電壓源。pin11所接的上拉電阻可以不要,但要設置相應的AVR輸入端口上拉電阻使能。pin13做為轉換結束指示,可以通過判斷此腳電平來決定是否可以讀出轉換數據,也可以簡單的使用延時的方法來留夠轉換時間。pin16、pin15、pin14、pin12做為一個標準的SPI從機接口與mega16芯片相連接。

        ADS7846支持8位精度和12位精度,即觸摸分辨率可以達到1/256或者1/4096,根據不同分辨率的LCD來選擇相應的觸摸精度。比如128×64的LCD可以采用8位精度,320×240的LCD需要采用12位精度。采集后的數據分兩次讀出,8位精度的先得到前7位再得到最后一位,12位精度的先得到前7位再得到后5位。

        程序段如下:(編譯器使用ICCAVR)



        /********************************************************************
        SPI Interface file
        crystal: 8MHz
        write by han, hanembed@126.com, http://embed.hanyuer.net
        ********************************************************************/

        #include iom16v.h>
        #include macros.h>

        /*===================================================================
        // function: initialize spi interface
        // in: void
        // retun: void
        // date: 2005/8/10
        ===================================================================*/
        void spiinit(void)
        {
        DDRB = (1 PB4) | (1 PB5) | (1 PB7); // MOSI and SCK port out
        PORTB |= (1 PB4);
        SPCR = (1 SPE) | (1 MSTR) | (0 SPR0); // enable spi,master mode, MCLK/4,spi 0 mode
        }

        /*===================================================================
        // function: send data form spi interface
        // in: unsigned char real data
        // retun: void
        // date: 2005/8/10
        ===================================================================*/
        void sendspi(unsigned char data)
        {
        SPDR = data; // send data
        while( !(SPSR (1 SPIF)) ); // wait data transfer end
        }

        /*===================================================================
        // function: receive data form spi interface
        // in: void
        // retun: unsigned char
        // date: 2005/8/10
        ===================================================================*/
        unsigned char readspi(void)
        {
        return SPDR;
        }

         

        /********************************************************************
        touch data read file
        crystal: 8MHz
        write by han, hanembed@126.com, http://embed.hanyuer.net
        ********************************************************************/

        #include iom16v.h>
        #include macros.h>
        #include ..incspi.h

        unsigned int positionx;
        unsigned int positiony;
        unsigned char flgtouch;

        /*========================Extern Interrupt==========================*/
        #pragma interrupt_handler keydown: iv_INT1

        /*===================================================================
        // function: initialize all used port
        // in: void
        // retun: void
        // date: 2005/8/10
        ===================================================================*/
        void portini(void)
        {
        spiinit();
        endspi();
        DDRD = ~(1 PD3); // port input
        PORTD |= (1 PD3); // pull-up resistance
        //MCUCR |= 1ISC11; // down edge enable
        GICR |= 1INT1; // extern interrupt 1 enable
        flgtouch = 0;
        }

        /*===================================================================
        // function: small delay
        // in: unsigned char delay times
        // retun: void
        // date: 2005/8/10
        ===================================================================*/
        void smalldelay(unsigned char tmp)
        {
        unsigned char i;
        while(tmp--)
        {
        for(i = 0; i 250; i++)
        {
        NOP();
        }
        }
        }

        /*===================================================================
        // function: read touch data
        // in: void
        // retun: void
        // date: 2005/8/10
        ===================================================================*/
        void keydown(void)
        {
        unsigned char tmp; // temporary data
        smalldelay(20); // delay wait tranquilization
        startspi(); // begin data transfer
        smalldelay(1);
        sendspi(0x90); // difference conversion, x data
        smalldelay(2); // delay wait x conversion
        sendspi(0x00);
        tmp = readspi(); // first 7 bit x data
        if(tmp == 0x7F) // error read
        return;
        positionx = tmp;
        positionx = 5; // left shift 5 bit
        sendspi(0xD0); // difference conversion, y data
        tmp = readspi(); // last 5 bit x data
        tmp >>= 3; // right shift 3 bit
        positionx += tmp; // real x data
        smalldelay(2); // delay wait y conversion
        sendspi(0x00);
        tmp = readspi(); // first 7 bit y data
        positiony = tmp;
        positiony = 5;
        sendspi(0x00); // only for read last y data
        tmp = readspi();
        tmp >>= 3;
        positiony += tmp; // real y data
        endspi();
        }

        經過簡單調試,筆者編寫了一個PC端軟件以顯示在上滑過的字符,一塊8×5cm的上約可以寫四行漢字,如下圖所示:



        圖中的若干零散點是由于硬件并沒有做抗干擾濾波,mcu程序中也沒有對接觸點進行重復讀取所致,一般可使用讀取兩次,重復數據為正確數據的方法來排除干擾。



        關鍵詞: Atmega16 觸摸屏

        評論


        相關推薦

        技術專區(qū)

        關閉