九层妖塔 起于垒土
一、分类:电阻屏 or 电容屏
触摸屏基本原理介绍
触摸屏工作原理解析
STM32CubeMX系列|触摸屏
二、淘晶驰电容触摸串口屏
三、上位机
四、MCU
main.c
#include <STC15.H>
#include <intrins.h>
#include <UART.H>
#define uchar unsigned char
#define uint unsigned int
uchar Receive;
uchar S1_num;
uchar S4_num;
void GPIO(void); //IO口初始化函数
void Delay10ms(); //@11.0592MHz
void main(void)
{
GPIO();
UartInit(); //串行口1初始化函数
ES=1;
EA=1;
S1 = 1 ; S2 = 1; S3 = 0; S4 = 0; S5 = 0;
while(1)
{
// UART_Send_start();//为确保串口HMI正常通信
// UART_Send_Str("page0.t0.txt=\"灯1亮\"");
// UART_Send_END();
// Delay10ms();
//
// UART_Send_start();//为确保串口HMI正常通信
// UART_Send_Str("page0.t0.txt=\"灯1灭\"");
// UART_Send_END();
}
}
//-----------------------------------IO口初始化函数-----------------------------//
void GPIO(void)
{
P0M1=0;
P0M0=0;
P1M1=0;
P1M0=0;
P2M1=0;
P2M0=0;
P3M1=0;
P3M0=0;
P4M1=0;
P4M0=0;
P5M1=0;
P5M0=0;
}
UART.H
#ifndef _UART_H_
#define _UART_H_
#include <STC15.H>
#define uchar unsigned char
#define uint unsigned int
sbit S1 = P0^0;
sbit S2 = P0^1;
sbit S3 = P0^2;
sbit S4 = P0^3;
sbit S5 = P0^4;
extern uchar Receive;
void UartInit(void); //9600bps@11.0592MHz 串行口1初始化函数
void UART_Send_Byte(unsigned char dat); //发送一个字节 串行发送采用查询方式
void UART_Send_Str(char *s);
void UART_Send_END(void);
void UART_Send_start(void);
void Delay10ms(); //@11.0592MHz
#endif
UART.c
#include <UART.H>
#include <intrins.h>
//-------------------------------------串行口1初始化函数-----------------------------//
void UartInit(void) //9600bps@11.0592MHz
{
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x40; //定时器1时钟为Fosc,即1T
AUXR &= 0xFE; //串口1选择定时器1为波特率发生器
TMOD &= 0x0F; //设定定时器1为16位自动重装方式
TL1 = 0xE0; //设定定时初值
TH1 = 0xFE; //设定定时初值
ET1 = 0; //禁止定时器1中断
TR1 = 1; //启动定时器1
}
void UART_Send_Byte(unsigned char dat) //发送一个字节 串行发送采用查询方式
{
//ES=0; //关串行口1中断
TI=0; //清除发送中断标志位
SBUF=dat; //将数据写入缓冲区
while(!TI);//等待发送结束
TI=0;
}
void UART_Send_Str(char *s) //发送一个字符串
{
int i=0;
while(s[i]!=0)
{
UART_Send_Byte(s[i]);
i++;
}
}
void UART_Send_END(void) //发送结束信号
{
UART_Send_Byte(0xFF);
UART_Send_Byte(0xFF);
UART_Send_Byte(0xFF);
}
void UART_Send_start(void)
{
Delay10ms();
UART_Send_END();
Delay10ms();
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
void uart_isr() interrupt 4
{
if(RI==1)
{
RI=0; //清除RI位
Receive=SBUF;
switch(Receive)
{
case 0X01: {S1 = 0 ; S2 = 1; S3 = 0; S4 = 0; S5 = 1;} break; //交越
case 0X02: {S1 = 1 ; S2 = 1; S3 = 0; S4 = 0; S5 = 0;} break; //标准
case 0X03: {S1 = 1 ; S2 = 0; S3 = 0; S4 = 0; S5 = 0;} break; //顶部
case 0X04: {S1 = 1 ; S2 = 1; S3 = 1; S4 = 0; S5 = 0;} break; //底部
case 0X05: {S1 = 1 ; S2 = 1; S3 = 0; S4 = 1; S5 = 0;} break; //双向
}
}
}