BF533和触摸屏接口芯片TSC2200调试日志

问了一下亿旗,终于调出来了,下面是部分源代码:
//************************************************// //** file: spi.c //** target: ADSP-BF533 //** creat time: 2008-8-19 #include <ccblkfn.h> #include <cdefBF533.h> #include "sys_func.h" //SPI interface funtion void SPI_Init(void) { *pSPI_BAUD = (unsigned short)(GetSCLK() / (2 * 5000000)); // 5MHz //SPI enable,master mode,CPHA=1(control by software), //16 bit,Start transfer with write of SPI_TDBR *pSPI_CTL = 0x5501; *pSPI_FLG = 0xFF20; // SPISEL5 enabled } //SPI send a word function void SPI_send_data(unsigned short data) { *pSPI_TDBR = data; while ((*pSPI_STAT & 0x0001) == 0) ; Delay(1000); } //SPI receive a word function unsigned short SPI_receive_data(void) { SPI_send_data(0xFFFF); return (*pSPI_RDBR); } //SPI RDBR clear void SPI_RDBR_Clr(void) { unsigned char buf; while (*pSPI_STAT & 0x0020) buf = *pSPI_RDBR; } //*********************************************************// #include <ccblkfn.h> #include <cdefBF533.h> #include <stdio.h> #include "tsc2200_exp.h" #include "sys_res.h" #include "segled.h" #include "sys_func.h" #include "uart.h" #include "spi.h" //Read value of a register of TSC2200 unsigned short TSC2200_Read(unsigned short addr) { unsigned short temp; SPI_SEL_LOW; //Clear SS low SPI_send_data(TSC_CMD_READ | addr); SPI_RDBR_Clr(); // Clear receiver buffer temp = SPI_receive_data(); SPI_SEL_HIGH; //Set SS high return temp; } //Write value to the register of TSC2200 void TSC2200_Write(unsigned short addr,unsigned short data) { SPI_SEL_LOW; //Clear SS low Delay(100); SPI_send_data(addr); SPI_send_data(data); Delay(100); SPI_SEL_HIGH; //Set SS high } //Check if the TSC2200 is exist bool Detect_TSC2200(void) { TSC2200_Write(TSC_CMD_RESET,RESET_RESET); //Reset the TSC2200 Delay(100); return (TSC2200_Read(TSC_CMD_ADC) == 0x4000); //0x4000 is the default value of reg ADC } //Initial the TSC2200 void TSC2200_Init(void) { TSC2200_Write(TSC_CMD_RESET,RESET_RESET); //Reset the TSC2200 Delay(100); TSC2200_Write(TSC_CMD_ADC, 0xC4A2);Delay(100);//Stop ADC convertor TSC2200_Write(TSC_CMD_REF, 0x0017);Delay(100); TSC2200_Write(TSC_CMD_CFG, 0x000A);Delay(100); TSC2200_Write(TSC_CMD_ADC, 0x07FF);Delay(100); // Put TSC to Host and slowest mode TSC2200_Write(TSC_CMD_ADC, 0x84A2);Delay(100); // Setup ADC,TSC control,Read XYZ,12 bit,8 bytes average } //Check if data is available bool TSC2200DataAvailable(void) { return ((TSC2200_Read(TSC_CMD_CFG) & CFG_DAVB) == 0x0000); } //Read the X Y coordinates void TSC2200ReadXY(unsigned short *px,unsigned short *py) { *px = TSC2200_Read(TSC_CMD_X); *py = TSC2200_Read(TSC_CMD_Y); } void Tsc2200_Exp(void) { unsigned short temp = 0x0000,x,y; //Store the X,Y SPI_SELECT_TSC2200; // Set SPI select pin to TSC2200 while(!Detect_TSC2200()) printf("No TSC2200 exist!/n"); printf("TSC2200 exist!/n"); TSC2200_Init(); while (1) { if (!(TSC2200_Read(TSC_CMD_CFG) & CFG_DAVB)) { ledblk(); TSC2200ReadXY(&x,&y); printf("X=%d;Y=%d;/n",x,y); } } }

你可能感兴趣的:(BF533和触摸屏接口芯片TSC2200调试日志)