archive: homework4 homework1
This commit is contained in:
@@ -18,9 +18,7 @@
|
|||||||
},
|
},
|
||||||
"targets": {
|
"targets": {
|
||||||
"Debug": {
|
"Debug": {
|
||||||
"excludeList": [
|
"excludeList": [],
|
||||||
"src/test1.c"
|
|
||||||
],
|
|
||||||
"toolchain": "Keil_C51",
|
"toolchain": "Keil_C51",
|
||||||
"compileConfig": {
|
"compileConfig": {
|
||||||
"options": "null"
|
"options": "null"
|
||||||
|
|||||||
@@ -29,18 +29,18 @@ sbit BUS8DP = P2 ^ 7;
|
|||||||
void set_38_2LED()
|
void set_38_2LED()
|
||||||
{
|
{
|
||||||
// e.g. set Y3 to 1, others to 0:
|
// e.g. set Y3 to 1, others to 0:
|
||||||
ADDR0 = 0;
|
ADDR0 = 1;
|
||||||
ADDR1 = 1;
|
ADDR1 = 1;
|
||||||
ADDR2 = 1;
|
ADDR2 = 0;
|
||||||
ADDR3 = 1;
|
ADDR3 = 1;
|
||||||
ENLED = 0;
|
ENLED = 0;
|
||||||
}
|
}
|
||||||
void set_38_2SEG()
|
void set_38_2SEG()
|
||||||
{
|
{
|
||||||
// e.g. set Y4 to 1, others to 0:
|
// e.g. set Y4 to 1, others to 0:
|
||||||
ADDR0 = 1;
|
ADDR0 = 0;
|
||||||
ADDR1 = 0;
|
ADDR1 = 0;
|
||||||
ADDR2 = 0;
|
ADDR2 = 1;
|
||||||
ADDR3 = 1;
|
ADDR3 = 1;
|
||||||
ENLED = 0;
|
ENLED = 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// test1.c
|
||||||
|
// 通过定时器实现以0.5Hz的频率闪烁一个小灯
|
||||||
|
#include "homework4.h"
|
||||||
|
|
||||||
|
unsigned char cnt = 0; // log timer T0 overflow counts
|
||||||
|
|
||||||
|
void test1()
|
||||||
|
{
|
||||||
|
set_38_2LED();
|
||||||
|
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
|
||||||
|
BUS1A = ~BUS1A; // toggle LED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
test1();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user