arm开发板触摸

主程序

#include "s5pv210.h"
#include "stdio.h"
#include "usdf.h"//如果在本目录下没找到此文件,就会去找框架里的include目录

void EXTI4_IRQHandler(void);
void Eint14_init(void);
void I2c_Init();
void I2c_PortInit();
void FT5x06_WR_Reg(unsigned char wrReg,unsigned char *wrData);

//
void led_init();
//

#define CT_CMD_WR	   	0X70	//写数据命令 011 1010 0
#define CT_CMD_RD   	       0X71	//读数据命令 011 1010 1
#define CT_MAX_TOUCH    5		//电容触摸屏最大支持的点数

unsigned char buf[34],num;


void FT5x06_test(void)
{
	unsigned char ft_module=0x0;
	Eint14_init();

	//Ft5x06 init 
  	I2c_PortInit();	
  	//
  	 led_init();
  	//
  	I2c_Init();
  	FT5x06_WR_Reg(0x0,&ft_module);

	while(1);
}

void _delay_ms(int cnt)
{
	volatile int i,j;
	for(i=0;i<0x100;i++)
		for(j=0;j<cnt;j++);
}

void Eint14_init(void)
{
	rGPH1CON |=(0xf<<24);
	rGPH1PUD &=~(0x3<<12);
	rGPH1PUD |=(0x2<<12);

	//ext init
	rEXT_INT_1_CON &=~(0x7<<24);
	rEXT_INT_1_CON |=(0x2<<24);

	rEXT_INT_1_MASK &=~(0x1<<6);
	rEXT_INT_1_PEND |=(0x1<<6);

	//vic0 init
	rVIC0INTENCLEAR |=(0x1<<14);
	rVIC0INTSELECT &=~(0x1<<14);
	(*(volatile unsigned long *)0xf2000138)= (unsigned long)EXTI4_IRQHandler;

	rVIC0ADDRESS = 0x0;
	rVIC0INTENABLE |=(0x1<<14);
}

void I2c_Init()
{
	rI2CCON2 = (1<<7)|(0<<6)|(1<<5)|(0<<4)|(0xf); //just setup ack (1<<7)
    	rI2CSTAT2 |= (0x1<<4);   	//make sure to init it

}

void I2c_PortInit()
{
	rGPD1CON &=~(0xff<<16); 
	rGPD1CON |=(0x22<<16);

	rGPD1PUD &=~(0xf<<8);
	rGPD1PUD |=(0xa<<8);
}

void FT5x06_WR_Reg(unsigned char wrReg,unsigned char *wrData)
{
	unsigned char i;
	//(1)发送起始信号设备地址,读写操作(这里为写)
	rI2CSTAT2 |=(3<<6);
	rI2CDS2 = CT_CMD_WR;
	
	rI2CSTAT2 |= (1<<5);
	rI2CCON2 &=~(1<<4);
	while(!(rI2CCON2&(1<<4)));

	//(2)发送要写的寄存器地址
	rI2CDS2 = wrReg;
	rI2CCON2 &=~(1<<4);
	while(!(rI2CCON2&(1<<4)));

	//(3)发送写入的内容
	rI2CDS2 = *wrData;
	rI2CCON2 &=~(1<<4);
	while(!(rI2CCON2&(1<<4)));

	//(4)发送停止信号
	rI2CSTAT2 &= ~(1<<5);
	rI2CCON2 &=~(1<<4);
	_delay_ms(0x20);
}

void FT5x06_RD_Reg(unsigned char rdReg,unsigned char *rdData)
{
	unsigned char i;
	//(1)发送起始信号和设备的地址信息和要进行的读写操作(在这里为写)
	rI2CSTAT2 |=(3<<6);//config to transmit mode 
	rI2CDS2 = CT_CMD_WR;//write data shift register from device addr and r/w cmd

    
	rI2CSTAT2 |= (1<<5);		//start transmit
	rI2CCON2 &=~(1<<4);		//clear interrupt pending
    	while(!(rI2CCON2&(1<<4)));//waiting for end of transmit interrupt

	//(2)发送要读取的寄存器的8位地址
	rI2CDS2 = rdReg;
    	rI2CCON2 &=~(1<<4);		
    	while(!(rI2CCON2&(1<<4)));
 

	//(2.1)发送停止位
    	rI2CSTAT2 &= ~(1<<5);
	rI2CCON2 &=~(1<<4);	
	_delay_ms(0x20);


	//(3)重新发送起始信号和读写操作(在这里为读)
    	rI2CSTAT2 |=(0x1<<7); 
    	rI2CSTAT2 &=~(0x1<<6);//config to receive mode

	rI2CDS2 = CT_CMD_RD;	
	rI2CSTAT2 |= (1<<5);
	rI2CCON2 &=~(1<<4);
    	while(!(rI2CCON2&(1<<4)));
	rI2CCON2 &=~(1<<4);	
	while(!(rI2CCON2&(1<<4)));

	//(4)读取数据
	*rdData=rI2CDS2; 
	rI2CCON2 &=~(0x1<<7); 		//disable ack
			
	rI2CCON2 &=~(1<<4);	
	while(!(rI2CCON2&(1<<4)));
	//(5)发送停止信号
    	rI2CSTAT2 &= ~(1<<5);

	//(6)收尾工作
	rI2CCON2 |=(1<<7);//enable ack
	rI2CCON2 &=~(1<<4);	
	_delay_ms(0x20);
}
//
void led_init()
{
	//GPJ2CON[3:0] = 0B0001
	rGPJ2CON &=~(0xffff<<0);
	rGPJ2CON |=(0x1111<<0);
	//GPJ2DAT[0] = 0/1 
	rGPJ2DAT |=(0xf<<0);
}
//
void EXTI4_IRQHandler(void)
{  	
	/*unsigned short x1,x2,y1,y2;	
	unsigned char i;*/

	unsigned char temp;
	unsigned short x,y;

	// unsigned char buf[20];

	_delay_ms(0x30);
	FT5x06_RD_Reg(0x2,&num);
	printf("num = %x\r\n", num&0x07);

	if(num<=5 && num>0)
	{
		switch(num) {
			case 1:
				FT5x06_RD_Reg(0x3,&temp);
				x = temp;
				FT5x06_RD_Reg(0x4,&temp);
				x = ((x &(0x000f)) <<8)|(temp);

				FT5x06_RD_Reg(0x5,&temp);
				y = temp;
				FT5x06_RD_Reg(0x6,&temp);
				y = ((y &(0x000f)) <<8)|(temp);
				printf("point1 x=%d,y=%d\n",x,y);
				// 这里可以判断x,y的坐标然后进行点灯等操作
					rGPJ2DAT &=~(0x1);
				// 
				break;
		}
	}
	rVIC0ADDRESS = 0x0;
	rEXT_INT_1_PEND |=(0x1<<6);	
	_delay_ms(0x30);

}


usdf.h把相关的寄存器地址写到这里,方便被其他程序调用。

#ifndef __USDF_H<span style="white-space:pre">	</span>//判断如果没有定义__USDF_H,下面就define定义,然后其他程序调用即可。
#define __USDF_H


#define rTCNTB0  (*(volatile unsigned int *)0xe250000c)
#define rTCMPB0  (*(volatile unsigned int *)0xe2500010)

#define rBCDSEC  (*(volatile unsigned int *)0xe2800070)
#define rBCDMIN  (*(volatile unsigned int *)0xe2800074)
#define rBCDHOUR  (*(volatile unsigned int *)0xe2800078)
#define rBCDDAY  (*(volatile unsigned int *)0xe280007c)
#define rBCDDAYWEEK  (*(volatile unsigned int *)0xe2800080)
#define rBCDMON  (*(volatile unsigned int *)0xe2800084)
#define rBCDYEAR  (*(volatile unsigned int *)0xe2800088)

#define rRTCCON (*(volatile unsigned int *)0xe2800040)
#define rCURTICCNT (*(volatile unsigned int *) 0xe2800090)


#define rGPD1CON (*(volatile unsigned int *) 0xe02000c0)
#define rGPD1PUD (*(volatile unsigned int *) 0xe02000c8)
#define rI2CSTAT2 (*(volatile unsigned int *) 0xe1a00004 )
#define rI2CDS2 (*(volatile unsigned int *) 0xe1a0000c)
#define rI2CCON2 (*(volatile unsigned int *) 0xe1a00000)
#define rGPH1CON (*(volatile unsigned int *) 0xe0200c20)
#define rGPH1PUD (*(volatile unsigned int *) 0xe0200c28)


#endif


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值