|
|
|
|
 |
触摸屏芯片ADS7846/ADS7843驱动程序(C51)
|
|
|
|
文章编号: |
081208125810 |
文章分类: |
单片机 > 51系列 |
|
点 击: |
|
关 键 词: |
ADS7846,ADS7843,触摸屏 |
|
文章来源: |
网络 |
|
摘 要: |
8051单片机驱动ADS7846/ADS7843芯片,ADS7846/7843芯片 适合用在4线制触摸屏,它通过标准SPI协议和CPU通信,操作简单,精度高,当触摸屏被按下时(即有触摸事件发生)则ADS7846向CPU发中断请求... |
|
-
-
-
-
-
-
-
-
- #include "reg51.h"
- #include "intrins.h"
-
- sbit DCLK=P1^6;
- sbit CS=P2^2;
- sbit DIN=P2^3;
- sbit DOUT=P2^4;
- sbit BUSY=P2^5;
-
- delay(unsigned char i--)
- {
- while(i--);
- }
-
- void start()
- {
- DCLK=0;
- CS=1;
- DIN=1;
- DCLK=1;
- CS=0;
- }
-
- WriteCharTo7843(unsigned char num)
- {
- unsigned char count=0;
- DCLK=0;
- for(count=0;count<8;count++)
- {
- num<<=1;
- DIN=CY;
- DCLK=0; _nop_();_nop_();_nop_();
- DCLK=1; _nop_();_nop_();_nop_();
- }
- }
-
-
- ReadFromCharFrom7843()
- {
- unsigned char count=0;
- unsigned int Num=0;
- for(count=0;count<12;count++)
- {
- Num<<=1;
- DCLK=1; _nop_();_nop_();_nop_();
- DCLK=0; _nop_();_nop_();_nop_();
- if(DOUT) Num++;
- }
- return(Num);
- }
-
- void ZhongDuan() interrupt 0
- {
- unsigned int X=0,Y=0;
- delay(10000);
- start();
-
- delay(2);
- WriteCharTo7843(0x90);
-
- delay(2);
- DCLK=1; _nop_();_nop_();_nop_();_nop_();
- DCLK=0; _nop_();_nop_();_nop_();_nop_();
- X=ReadFromCharFrom7843();
- WriteCharTo7843(0xD0);
- DCLK=1; _nop_();_nop_();_nop_();_nop_();
- DCLK=0; _nop_();_nop_();_nop_();_nop_();
- Y=ReadFromCharFrom7843();
- CS=1;
- }
-
-
- main()
- {
- TMOD=0x11;
- TCON=0x00;
- IE=0x83;
- IP=0x01;
- while(1);
- }
|
|
|
|
|
|
|
|
|
|
|