当前位置:网站首页>Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
2022-07-02 05:55:00 【I don't know who】
Select different functions in the serial port sending menu interface
One 、 subject
Use serial port 1、 Timer T1 The pattern of 0 As a baud rate generator STC Serial port communication between the experimental box and the host computer ,STC Through serial port 1 Send the menu interface to the host , Host empty STC In the experimental box LED The lamp .
1) On a host computer , Press 1 key , Used to control the STC The test box is marked LED17( Connect to P6.7 On ) Of LED The lamp ;
2) Press 2 key , Used to control the STC The test box is marked LED16( Connect to P6.6 On ) Of LED The lamp ;
3) Press other keys to display information about exiting the program .
Two 、 Code
#include "STC8h.h"
#include <intrins.H>
typedef unsigned char uchar;
typedef unsigned int uint;
bit busy;
u8 Flag;
uchar GetC;
sbit control=P4^0;
void InitUART(void);
void SendData(uchar dat);
void SendString(uchar *s);
void gpio() //gpio Initialize to quasi two-way port , At first, except P30,P31 Others are in high resistance state
{
P0M1 = 0x00; P0M0 = 0x00; // Set as quasi two-way port
P1M1 = 0x00; P1M0 = 0x00; // Set as quasi two-way port
P2M1 = 0x00; P2M0 = 0x00; // Set as quasi two-way port
P3M1 = 0x00; P3M0 = 0x00; // Set as quasi two-way port
P4M1 = 0x00; P4M0 = 0x00; // Set as quasi two-way port
P5M1 = 0x00; P5M0 = 0x00; // Set as quasi two-way port
P6M1 = 0x00; P6M0 = 0x00; // Set as quasi two-way port
P7M1 = 0x00; P7M0 = 0x00; // Set as quasi two-way port
}
void main()
{
control=0;
gpio();
P0=0xff;
InitUART();
SendString("---------main menu----------\r\n input 1: Control LED7\r\n input 2: Control LED6\r\n other : exit program\r\n---------end menu----------\r\n");
while(1)
{
if(Flag==1)
{
SendData(GetC);
Flag=0;
}else if(Flag==2)
{
SendString("Exited program\r\n");
Flag=0;
}
}
}
/*---------------------------- UART1 initialization -----------------------------*/
void InitUART(void)
{
SCON = 0x50; //8 Bit data
P_SW1= P_SW1 & 0x3F;
AUXR |= 0x40; // Timer 1T Pattern
AUXR &= 0xFE;
TMOD &= 0x0F;
TMOD |= 0x20; //8 Bit auto reload mode
TL1 = 0xDC; //
TH1 = 0xDC;
TR1 = 1; // Turn on timer 1
ES = 1; // Enable serial port interrupt
EA = 1;
}
/*---------------------------- UART interrupt -----------------------------*/
void Uart() interrupt 4 using 1
{
if (RI)
{
RI = 0; // After receiving characters ,RI clear 0
GetC = SBUF;
if (GetC=='1') {
P6=0x7f;P0=0X7F;Flag=1;}
if (GetC=='2') {
P6=0xbf;P0=0XBF;Flag=1;}
if(GetC!='1'&&GetC!='2') {
Flag=2;}
}
if (TI)
{
TI = 0; // After sending characters TI clear 0
busy = 0; // After sending one character busy clear 0
}
}
/*---------------------------- Send byte ----------------------------*/
void SendData(uchar dat)
{
while (busy);
busy = 1;
SBUF = dat; // The data to be sent is stored SBUF
}
/*---------------------------- Send string function ----------------------------*/
void SendString(uchar *s)
{
while (*s !='\0') // The string is read before it stops
{
SendData(*s++); // Every byte sent s++
}
}
summary
At present, I have updated a series of SCM articles , Welcome to the homepage .
Thank you very much for watching !!!
Series articles ——STC8H8K Series compilation 51 actual combat
STC8H8K Series compilation and C51 actual combat —— Realize the running lantern (51 edition )
STC8H8K Series compilation and C51 actual combat —— Realize the running lantern ( Assembly Edition )
STC8H8K Series compilation and C51 actual combat —— Switch control Timer Stopwatch (C51 edition )
STC8H8K Series compilation and C51 actual combat —— Dual interrupt control timer flow lamp
STC8H8K Series compilation and C51 actual combat —— Double interrupt plus and minus counter
STC8H8K Series compilation and C51 actual combat —— Simple frequency meter
STC8H8K Series compilation and C51 actual combat —— Second countdown timer ( Assembly Edition )
STC8H8K Series compilation and C51 actual combat —— Second countdown timer (51 edition )
STC8H8K Series compilation and C51 actual combat —— Keys allow key counts (51 edition )
STC8H8K Series compilation and C51 actual combat —— Keys allow key counts ( Assembly Edition )
边栏推荐
- 数理统计与机器学习
- Opencv LBP features
- php内类名称与类内方法名相同
- Redis key value database [primary]
- Grbl software: basic knowledge of simple explanation
- [personal test] copy and paste code between VirtualBox virtual machine and local
- Pytorch Basics
- Matplotlib double Y axis + adjust legend position
- 我所理解的DRM显示框架
- [paper translation] gcnet: non local networks meet squeeze exception networks and beyond
猜你喜欢

OLED12864 液晶屏

Grbl software: basic knowledge of simple explanation

Stick to the big screen UI, finereport development diary

Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan

Eco express micro engine system has supported one click deployment to cloud hosting

Test case

文件包含漏洞(二)

2022-2-15 learning xiangniuke project - Section 8 check login status

RGB infinite cube (advanced version)

CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
随机推荐
PHP extensions
Go 学习笔记整合
I want to understand the swift code before I learn it. I understand it
JS determines whether the mobile terminal or the PC terminal
php按照指定字符,获取字符串中的部分值,并重组剩余字符串为新的数组
Huawei Hongmeng OS, is it OK?
“簡單”的無限魔方
Zzuli:1069 learn from classmate Z
Redis key value database [primary]
软件测试答疑篇
Can't the dist packaged by vite be opened directly in the browser
Reading notes of cgnf: conditional graph neural fields
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
图片裁剪插件cropper.js
Common protocols and download paths of NR
ES6的详细注解
页面打印插件print.js
如何写出好代码 — 防御式编程指南
Cube magique infini "simple"
Web页面用户分步操作引导插件driver.js