当前位置:网站首页>Sixteen system counter and flow lamp
Sixteen system counter and flow lamp
2022-06-29 10:08:00 【It's mally!】
51 do Sixteen system counter and water lamp
Notes
This article focuses on the use of 51 Single chip timer interrupt , And in proteus Code to pay attention to in simulation .
Reference resources : Timer use demo,proteus Simulation
Hexadecimal counter
Subject requirements : use P0.0- P0.03 Design one in 0-15 A hexadecimal counter that automatically counts between , Hold each value 0.2s.
Code
#include<reg52.h>
void Timer0Init(void) //20 Microsecond @12.000MHz
{
TMOD = 0x02; // Set timer mode
TL0 = 0x10; // Set initial value of timing
TH0 = 0x10; // Set time overload value
EA=1; // General interruption
ET0=1; // On timer interrupt
TR0=1; // Start timer 0
TF0 = 0; // eliminate TF0 sign
TR0 = 1; // Timer 0 Start timing
}
int num=0;
int cnt=0;
void T0_time() interrupt 1
{
++num;
if(num==10000)
{
num=0;
cnt=(cnt+1)%16;
P0=cnt;
}
}
void main()
{
Timer0Init();
while(1);
}
Circuit diagram

Code interpretation
setp1: The timing part of the code can use stc-isp Generate , But it needs to be revised

step2:
. however AUXR Is an extended register , yes 51 The enhanced version of , and proteus There is no , So delete this line .
step3: Add interrupt

(from In the manual 8 Bit auto reassembly )
Know to open interrupt 1, add to
EA=1; // General interruption
ET0=1; // On timer interrupt
step4: Calculation 0.2s from How many? 20 μ s 20\mu s 20μs form
use 8 Bit automatic overload generation 10 Microsecond interrupt .
1 μ s = 1 0 − 6 s 1 m s = 1 0 − 3 s because this 0.2 s = 200 m s = 2 ∗ 1 0 5 μ s = 1 0 4 ∗ 20 μ s 1\mu s=10^{-6}s\\ 1 ms =10^{-3}s\\ therefore 0.2s=200ms=2*10^5\mu s=10^4*20\mu s 1μs=10−6s1ms=10−3s because this 0.2s=200ms=2∗105μs=104∗20μs
Running water lamp
Code
#include<reg52.h>
void delay(int a)
{
a=a*10;
while(a--);
}
void main()
{
int cnt=0;
int arr[]={1,2,4,8,16,32,64,128};
while(1)
{
P0=arr[cnt];
cnt=(cnt+1)%8;
delay(1000);
}
}
easy, Don't explain
On the basis of the above, a row of lights is added , The general drawing is

miscellaneous ( Don't look )
stc89c51 and AT89C51 difference ?
They are collectively referred to as 51 Single chip microcomputer
Why does the textbook learn 15 Single chip microcomputer , And it uses 51 Single chip microcomputer .、
SCM manual can be divided into stc Look for
Reference blog : Portal 1- Speaking of the external memory part
The teacher used a bread board to 15 Single chip microcomputer 4 Modes to test ,
Under different solutions and outputs , Observe led The light and dark of the lamp know the current of different modes .
STC15F2K60S2 All of SCM I/O Every mouth has 4 Working mode :: Quasi two-way port ( Tradition 8051 Single chip microcomputer I/O Pattern )、 Push pull output 、 Input only ( High resistance state ) And open drain mode
however proteus I won't support it 15 SCM simulation , and 51 SCM is an ancient SCM , Only quasi two-way port is used for this output mode ( It is a common open drain output plus pull ) Therefore, it is impossible to proteus Test this 4 The effects of these modes .
Small .
STC15F2K60S2 All of SCM I/O Every mouth has 4 Working mode :: Quasi two-way port ( Tradition 8051 Single chip microcomputer I/O Pattern )、 Push pull output 、 Input only ( High resistance state ) And open drain mode
however proteus I won't support it 15 SCM simulation , and 51 SCM is an ancient SCM , Only quasi two-way port is used for this output mode ( It is a common open drain output plus pull ) Therefore, it is impossible to proteus Test this 4 The effects of these modes .
边栏推荐
- Custom MVC framework implementation
- TLAB of JVM
- Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit
- 完美二叉树、完全二叉树、完满二叉树
- 2019.11.13训练总结
- Alternative implementation of Scrollview pull-down header amplification
- Slider validation code
- 使用Rancher搭建Kubernetes集群
- 共用体Union
- sympy的dsolve函数
猜你喜欢

2020-09-29 非商品模板化代码层次 rapidjson库

Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit

阿里云防火墙配置,多种设置方式(iptables和fireward)

C语言中通过sprintf()函数构造sql语句

Middle order traversal of Li Kou 94 binary tree

GridView of basic component of shutter

Constructing SQL statements by sprintf() function in C language

RecyclerView 粘性(悬浮)头部

Flutter 基础组件之 Text

Image of the basic component of the shutter
随机推荐
leetcode MYSQL数据库题目178
使用Rancher搭建Kubernetes集群
容器
Recyclerview refreshes blinks and crashes when deleting items
FreeRTOS(九)——队列
逆向思维-小故事
URAL1517 Freedom of Choice 【后缀数组:最长公共连续子串】
Codeforces Round #657 Div. 2
山科 的C语言2018练习题(电信)
2019.10.6训练总结
The Stones Game【取石子博弈 & 思维】
Middle order traversal of Li Kou 94 binary tree
float 与 int 相乘产生的令人崩溃的“ 2.3 * 10 = 22 ”
C语言实现一种创建易管理易维护线程的方法
IPC(进程间通信)之管道详解
在Activity外使用startActivity()方法报错原因与解决办法
sympy的dsolve函数
Codeforces Round #641 Div2
Leetcode MySQL database topic 181
Slider validation code