📄 touchpanal.c.bak_smart_update
字号:
/** ###################################################################
** Filename : touchpanal.C
** Project : touchpanal
** Processor : MC9S08QG8CDT
** Version : Driver 01.11
** Compiler : CodeWarrior HCS08 C Compiler
** Date/Time : 2007-9-14, 12:46
** Abstract :
** Main module.
** Here is to be placed user's code.
** Settings :
** Contents :
** No public methods
**
** (c) Copyright UNIS, spol. s r.o. 1997-2006
** UNIS, spol. s r.o.
** Jundrovska 33
** 624 00 Brno
** Czech Republic
** http : www.processorexpert.com
** mail : info@processorexpert.com
** ###################################################################*/
/* MODULE touchpanal */
/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "AS1.h"
#include "KBI1.h"
#include "Bit1.h"
#include "Bit2.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#define PenDetect PTAD_PTAD2
#define SPI_CS PTBD_PTBD5
#define BUSY 1
#define SETX (byte)0xD8 //D8 8bitADC VDD ref /PENIRQ enable
#define SETY (byte)0X98
#define FULL 1
#define BUSCLK 16000000 //16M
word X_coordinate, Y_coordinate;
/*=======================================================
* interrupt function here
*
*
=======================================================*/
bool Flag_SPI_reading=0;
bool Flag_SPI_reading_status=0;
void SPISendChar(unsigned char data) {
while (!SPIS_SPTEF && !PTBD_PTBD5); /* Wait until transmit buffer is empty */
SPI_CS= 0; /* Select slave */
SPID = data; /* Start to send data */
}
interrupt 18 void PENIRQ(void)
{
KBISC_KBIE = FALSE;
// if(!PenDetect){
// if(Flag_SPI_reading==0){
Flag_SPI_reading=1;
SPI_CS=0;
SPISendChar(SETX);
// }
// }
// Cpu_Delay100US(200);
// if (PTAD_PTAD2 == 0)
// Flag_SPI_reading = 1;
KBISC_KBACK = 1;
KBISC_KBIE = TRUE;
}
interrupt 12 void TIMER_int(void)
{
SPID=SETX;
// SPID=SETY;
}
char ReadTouchPanleStep=0;
interrupt 14 void SCI_ERR_int(void)
{
}
interrupt 15 void UART_RECEIVE_int(void)
{
}
char uart_transmit_data[10]={88, 0,0,0,0, 68};
char uart_transmit_point=0;
interrupt 16 void UART_TRANSMIT_int(void)
{
uart_transmit_point++;
if(uart_transmit_point<6)
SCID=uart_transmit_data[uart_transmit_point];
else
uart_transmit_point=0;
}
interrupt 13 void SPI_int(void)
{
char spi_temp=0;
switch (ReadTouchPanleStep){
case 0 : SPISendChar(0);
ReadTouchPanleStep++;
break;
case 1 : X_coordinate=SPID;
X_coordinate<<=5;
SPISendChar(SETY);
ReadTouchPanleStep++;
break;
case 2 : spi_temp= SPID;
X_coordinate+=(spi_temp>>3);
SPISendChar(0);
ReadTouchPanleStep++;
break;
case 3 : Y_coordinate=SPID;
Y_coordinate<<=5;
SPISendChar(0);
ReadTouchPanleStep++;
break;
case 4 : spi_temp= SPID;
Y_coordinate+=(spi_temp>>3);
ReadTouchPanleStep=0;
if(PenDetect){
Flag_SPI_reading=0;
SPI_CS=1;
}
else {
// SPISendChar(SETX);
ReadTouchPanleStep=0;
}
uart_transmit_data[1]=(byte)(X_coordinate>>8);
uart_transmit_data[2]=(byte)X_coordinate;
uart_transmit_data[3]=(byte)(Y_coordinate>>8);
uart_transmit_data[4]=(byte)Y_coordinate;
SCID=uart_transmit_data[0];
break;
default :
break;
}
}
/*==========================================================*/
// TWREG x_position,y_position;
void UART_init()
{
// SCIBDL = (byte)(BUSCLK/256/115200);
// SCIBDH = (byte)(((word)(BUSCLK/256/115200))>>8);
SCIBDL=0;
SCIBDH=0;
SCIC1 = 0;
SCIC2 = 0X0C;
SCIC3 = 0x20;
SCIS2 = 0x00;
}
void Timer_init()
{
MTIMCLK_CLKS1=1; //source select internal clock
MTIMCLK_PS3=1; //256 prescale
MTIMSC_TOIE=1; //timer interrrup enable
MTIMSC_TSTP=0; //strat timer
/* ### Init_TPM init code */
TPMMOD = 0xFFFF;
TPMC0V = 0xFFFF;
/* TPMC0SC: CH0F=0,CH0IE=0,MS0B=0,MS0A=1,ELS0B=0,ELS0A=1 */
TPMC0SC = 0x14;
TPMC1V = 0x4000;
/* TPMC1SC: CH1F=0,CH1IE=0,MS1B=1,MS1A=0,ELS1B=0,ELS1A=1 */
TPMC1SC = 0x24;
/* TPMSC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=1,PS0=0 */
TPMSC = 0x0A;
/* ### */
}
void SM1_Init(void)
{
// SerFlag = 0; /* Reset all flags */
//ErrFlag = 0; /* Reset all flags in mirror */
//SM1_EnEvent = TRUE; /* Enable events */
#pragma MESSAGE DISABLE C4002 /* Disable warning C4002 "Result not used" */
(void)SPIS; /* Read the status register */
(void)SPID; /* Read the device register */
/* SPIBR: ??=0,SPPR2=1,SPPR1=0,SPPR0=0,??=0,SPR2=0,SPR1=0,SPR0=0 */
setReg8(SPIBR, 0x44); /* Set the baud rate register */
/* SPIC2: ??=0,??=0,??=0,MODFEN=0,BIDIROE=0,??=0,SPISWAI=0,SPC0=0 */
setReg8(SPIC2, 0x00); /* Configure the SPI port - control register 2 */
/* SPIC1: SPIE=1,SPE=0,SPTIE=0,MSTR=1,CPOL=0,CPHA=1,SSOE=0,LSBFE=0 */
setReg8(SPIC1, 0x94); /* Configure the SPI port - control register 1 */
SPIC1_SPE = 1; /* Enable device */
}
void main(void)
{
asm CLI; /* Enable interrupts */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
Timer_init();
UART_init();
SM1_Init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
PTAPE_PTAPE2 =1; //pen pull up
SPIC1_CPOL=0;
SPIC1_CPHA=0;
while (1){
;
}
/* END touchpanal */
/*
** ###################################################################
**
** This file was created by UNIS Processor Expert 3.00 [03.89]
** for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -