当前位置:网站首页>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 )
边栏推荐
- Balsamiq wireframes free installation
- 2022-2-15 learning xiangniuke project - Section 8 check login status
- Fundamentals of software testing
- Pytorch Basics
- How to change the IP address of computer mobile phone simulator
- VSCode paste image插件保存图片路径设置
- Zzuli:1060 numbers in reverse order
- Software testing Q & A
- 1037 Magic Coupon
- token过期自动续费方案和实现
猜你喜欢
How vite is compatible with lower version browsers
keepalived安装使用与快速入门
Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond
Fundamentals of software testing
Redis Key-Value数据库【初级】
Oled12864 LCD screen
Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash
Software testing - concept
Pytorch Basics
memcached安装
随机推荐
PHP development and testing WebService (soap) -win
php内的addChild()、addAttribute()函数
Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash
软件测试 - 概念篇
492.构造矩形
[paper translation] gcnet: non local networks meet squeeze exception networks and beyond
Pytorch Chinese document
【C语言】简单实现扫雷游戏
运动健身的一些心得经验
MySQL transaction and isolation level
Zzuli:1069 learn from classmate Z
Matplotlib double Y axis + adjust legend position
Go language web development is very simple: use templates to separate views from logic
Huawei Hongmeng OS, is it OK?
1036 Boys vs Girls
Test case
Zzuli:1067 faulty odometer
Nacos 启动报错 Error creating bean with name ‘instanceOperatorClientImpl‘ defined in URL
How to write good code - Defensive Programming Guide
测试 - 用例篇