<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 基于MSP430F249的ADC7864觸摸程序函數

基于MSP430F249的ADC7864觸摸程序函數

作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò ) 收藏
這個(gè)例子是我參照51單片機的例子寫(xiě)的,測試過(guò),能正常讀取數據,沒(méi)轉換為坐標
使用的是中斷法,下降沿促發(fā)
//文件名:tourch_screen.h
//基于A(yíng)DS7846的觸摸屏程序
//宏定義:對管腳的定義
//
#ifndef _touch_screen_h_
#define _touch_screen_h_
extern unsigned int x_zb,y_zb; //測的x,y坐標
//函數:Touch_Port_Ini()
//描述:初始化觸摸控制端口
//返回值:無(wú)
void Touch_Port_Ini(); //初始化端口
#endif
//描述:管腳的宏定義
//
//
#ifdef _touch_
#include<msp430x24x.h>
#define tch_out P2OUT
#define tch_in P2IN
#define tch_dir P2DIR //觸摸控制端口
#define tch_ie P2IE //用來(lái)產(chǎn)生中斷
#define tch_ies P2IES
#define tch_ifg P2IFG
#define DCLK BIT0
#define DCLKSET() tch_out|=DCLK
#define DCLKCLR() tch_out&=~DCLK
#define DCS BIT1
#define CSSET() tch_out|=DCS
#define CSCLR() tch_out&=~DCS
#define SOUT BIT3
#define DOUT tch_in&SOUT //數據接受腳
#define DIN BIT2
#define DINSET() tch_out|=DIN
#define DINCLR() tch_out&=~DIN
#define DINIT BIT5
#define SBUSY BIT4
#define DBUSY tch_in&SBUSY //忙檢測
#endif
//文件名:tourch_screen.c
//基于A(yíng)DS7846的觸摸屏程序
//
//
#define _touch_
#include"touch_screen.h"
unsigned int x_zb=0,y_zb=0;
//函數:Touch_Port_Ini()
//描述:初始化觸摸控制端口
//返回值:無(wú)
void Touch_Port_Ini() //觸摸端口初始化
{
tch_dir|=DCLK|DCS|DIN; //設置端口方向
tch_dir&=~SOUT;
tch_ie|=DINIT; //設置允許中斷
tch_ies|=DINIT; //設置下降沿觸發(fā)
tch_ifg=0; //清中斷標志
_EINT(); //開(kāi)總中斷
}
//函數:Spi_Start()
//描述:和ADC7846數據傳輸開(kāi)始
//返回值:無(wú)
void Spi_Start() //spi開(kāi)始
{
CSSET();
DCLKCLR();
DINCLR();
CSCLR();
}
//函數:Write_7846()
//描述:對7843寫(xiě)數據
//返回值:無(wú)
void Write_7846(unsigned char num) //spi寫(xiě)數據
{
unsigned char i;
DCLKCLR();
for(i=0;i<8;i++)
{
if(num&0x80)
{
DINSET();
}
else
{
DINCLR();
}
DCLKCLR();_NOP();_NOP();_NOP();_NOP();
DCLKSET();_NOP();_NOP();_NOP();_NOP();
num<<=1;
}
}
//函數:Read12_7846()
//描述:讀7843的12位數據
//返回值:無(wú)
unsigned int Read12_7846() // SPI讀取數據
{
unsigned char i;
unsigned int data;
DCLKCLR();
for(i=0;i<12;i++)
{
data<<=1;
DCLKSET();_NOP();_NOP();_NOP();_NOP();
DCLKCLR();_NOP();_NOP();_NOP();_NOP();
if(DOUT) data++;
}
return data;
}
//函數:Read8_7846()
//描述:讀7843的8為數據
//返回值:無(wú)
unsigned char Read8_7846() // SPI讀取數據
{
unsigned char i;
unsigned char data;
DCLKCLR();
for(i=0;i<8;i++)
{
data<<=1;
DCLKSET();_NOP();_NOP();_NOP();_NOP();
DCLKCLR();_NOP();_NOP();_NOP();_NOP();
if(DOUT) data++;
}
return data;
}
//函數:delay_ADC7846()
//描述:延時(shí)函數
//返回值:無(wú)
void delay_ADC7846(unsigned int i)
{
unsigned char j;
for(;i>0;i--)
for(j=100;j>0;j--);
}
//12精度:讀y坐標寫(xiě)入0x90,x坐標寫(xiě)入0xd0
//8位精度:讀y坐標寫(xiě)入0x98,x坐標寫(xiě)入0xd8
//
#pragma vector=PORT2_VECTOR
__interrupt void touch_int()
{
unsigned int x,y;
delay_ADC7846(500);
Spi_Start();
delay_ADC7846(1);
Write_7846(0x98);
delay_ADC7846(1);
y=Read8_7846();
Write_7846(0xD8);
delay_ADC7846(1);
x=Read8_7846();
CSSET();
delay_ADC7846(10000);
if(x!=0&&y!=4095) //防止在結束時(shí)再讀取錯誤數據
{
x_zb=x;
y_zb=y;
}
tch_ifg=0; //清中斷標志位
}



評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>