archive: homework4 test1

This commit is contained in:
2025-04-12 23:28:07 +08:00
parent 9649e516b6
commit ba27e81369
3 changed files with 55 additions and 0 deletions
Binary file not shown.
+22
View File
@@ -0,0 +1,22 @@
// homework4.h
/*
* this file defines the pin numbers for the LED and 38 transistors.
*/
#include <REG52.H>
sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;
sbit ENLED = P1 ^ 4;
sbit D1 = P2 ^ 7;
sbit D2 = P2 ^ 6;
sbit D3 = P2 ^ 5;
sbit D4 = P2 ^ 4;
sbit D5 = P2 ^ 3;
sbit D6 = P2 ^ 2;
sbit D7 = P2 ^ 1;
sbit D8 = P2 ^ 0;
+33
View File
@@ -0,0 +1,33 @@
// test1.c
// 通过定时器实现以0.5Hz的频率闪烁一个小灯
#include "homework4.h"
unsigned char cnt = 0; // log timer T0 overflow counts
void main()
{
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
TMOD = 0x01; // timer T0 mode 1, 16-bit timer
TH0 = 0XB8;
TL0 = 0X00;
TR0 = 1; // timer T0 run
while (1) {
if (TF0 == 1) { // timer T0 overflow
TF0 = 0; // clear timer T0 overflow flag
TH0 = 0xB8; // reload timer T0 value
TL0 = 0x00;
cnt++; // log timer T0 overflow counts
if (cnt >= 50) {
cnt = 0; // clear log timer T0 overflow counts
D1 = ~D1; // toggle LED
}
}
}
}