当前位置:网站首页>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 )
边栏推荐
- 【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
- Redis Key-Value数据库 【高级】
- 深度学习分类网络--Network in Network
- php数组转化为xml
- 492.构造矩形
- servlet的web.xml配置详解(3.0)
- 页面打印插件print.js
- Redis key value database [seckill]
- 我所理解的DRM显示框架
- Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
猜你喜欢

脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四

Pytorch Basics

CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现

keepalived安装使用与快速入门

Spark概述

Fundamentals of software testing

Can't the dist packaged by vite be opened directly in the browser

Software testing Q & A

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

PHP development and testing WebService (soap) -win
随机推荐
PHP inner class name is the same as the inner class method name
RGB infinite cube (advanced version)
脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四
mock-用mockjs模拟后台返回数据
TI毫米波雷达学习(一)
Oled12864 LCD screen
Redis key value database [primary]
STC8H8K系列匯編和C51實戰——數碼管顯示ADC、按鍵串口回複按鍵號與ADC數值
Grbl software: basic knowledge of simple explanation
JS determines whether the mobile terminal or the PC terminal
PHP array to XML
【C语言】筛选法求素数
Mathematical statistics and machine learning
3D printer G code command: complete list and tutorial
软件测试基础篇
2022-2-15 learning xiangniuke project - Section 8 check login status
Go 学习笔记整合
Software testing Q & A
Some experience of exercise and fitness
Zzuli:1067 faulty odometer