archieve: homework5
This commit is contained in:
@@ -20,8 +20,9 @@
|
|||||||
"Debug": {
|
"Debug": {
|
||||||
"excludeList": [
|
"excludeList": [
|
||||||
"src/test.c",
|
"src/test.c",
|
||||||
"src/test1.c",
|
"src/test2.c",
|
||||||
"src/test2.c"
|
"src/test3.c",
|
||||||
|
"src/test4.c"
|
||||||
],
|
],
|
||||||
"toolchain": "Keil_C51",
|
"toolchain": "Keil_C51",
|
||||||
"compileConfig": {
|
"compileConfig": {
|
||||||
|
|||||||
+10
-7
@@ -5,17 +5,20 @@
|
|||||||
#include "homework5.h"
|
#include "homework5.h"
|
||||||
unsigned char LedBuff[6] = {
|
unsigned char LedBuff[6] = {
|
||||||
0xFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF};
|
0xFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF};
|
||||||
unsigned char i = 0;
|
unsigned char i = 0;
|
||||||
|
unsigned char display_id[6] = {1, 3, 0, 0, 7, 1};
|
||||||
|
|
||||||
void test1()
|
void test1()
|
||||||
{
|
{
|
||||||
// display the number on the Seg.
|
// display the number on the Seg.
|
||||||
LedBuff[5] = LedChar[1];
|
// 5 is high digit.
|
||||||
LedBuff[4] = LedChar[3];
|
// 0 is low digit.
|
||||||
LedBuff[3] = LedChar[0];
|
LedBuff[5] = LedChar[display_id[0]];
|
||||||
LedBuff[2] = LedChar[0];
|
LedBuff[4] = LedChar[display_id[1]];
|
||||||
LedBuff[1] = LedChar[7];
|
LedBuff[3] = LedChar[display_id[2]];
|
||||||
LedBuff[0] = LedChar[1];
|
LedBuff[2] = LedChar[display_id[3]];
|
||||||
|
LedBuff[1] = LedChar[display_id[4]];
|
||||||
|
LedBuff[0] = LedChar[display_id[5]];
|
||||||
while (1) {
|
while (1) {
|
||||||
/*
|
/*
|
||||||
* seg id on 38 transistors:
|
* seg id on 38 transistors:
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ void test2()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// log the number in the buffer.
|
// log the number in the buffer.
|
||||||
|
// 5 is high digit.
|
||||||
|
// 0 is low digit.
|
||||||
LedBuff[5] = LedChar[hour / 10]; // log the hour tens.
|
LedBuff[5] = LedChar[hour / 10]; // log the hour tens.
|
||||||
LedBuff[4] = LedChar[hour % 10]; // log the hour units.
|
LedBuff[4] = LedChar[hour % 10]; // log the hour units.
|
||||||
LedBuff[3] = LedChar[minute / 10]; // log the minute tens.
|
LedBuff[3] = LedChar[minute / 10]; // log the minute tens.
|
||||||
|
|||||||
@@ -13,10 +13,9 @@
|
|||||||
* 7. msksbr NB!!!
|
* 7. msksbr NB!!!
|
||||||
* 8. msksbr NB!!!
|
* 8. msksbr NB!!!
|
||||||
*/
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#include "homework5.h"
|
#include "homework5.h"
|
||||||
unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars.
|
unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars.
|
||||||
|
|
||||||
void test3()
|
void test3()
|
||||||
{
|
{
|
||||||
@@ -67,6 +66,8 @@ void test3()
|
|||||||
}
|
}
|
||||||
// log the number in the buffer.
|
// log the number in the buffer.
|
||||||
// only log the valid digits.
|
// only log the valid digits.
|
||||||
|
// 5 is high digit.
|
||||||
|
// 0 is low digit.
|
||||||
LedBuff[5] = hour >= 10 ? LedChar[hour / 10] : 0XFF; // log the hour tens.
|
LedBuff[5] = hour >= 10 ? LedChar[hour / 10] : 0XFF; // log the hour tens.
|
||||||
LedBuff[4] = hour > 0 ? LedChar[hour % 10] : 0XFF; // log the hour units.
|
LedBuff[4] = hour > 0 ? LedChar[hour % 10] : 0XFF; // log the hour units.
|
||||||
LedBuff[3] = (minute >= 10 || hour > 0) ? LedChar[minute / 10] : 0XFF; // log the minute tens.
|
LedBuff[3] = (minute >= 10 || hour > 0) ? LedChar[minute / 10] : 0XFF; // log the minute tens.
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
// test4.c
|
||||||
|
// 写一个从999999开始倒计时的秒表。并且改用定时器T1的中断来完成
|
||||||
|
// make a stopwatch that counts down from 999999. and use interrupt to finish it.
|
||||||
|
|
||||||
|
#include "homework5.h"
|
||||||
|
unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars.
|
||||||
|
volatile unsigned char i = 0; // to current digit.
|
||||||
|
volatile unsigned long display_time = 999999; // to store the time to display.
|
||||||
|
unsigned int cnt = 0; // to count interrupt.
|
||||||
|
|
||||||
|
// init timer
|
||||||
|
void initTimer(void)
|
||||||
|
{
|
||||||
|
TMOD &= 0x0F; // clear TMOD.
|
||||||
|
TMOD |= 0x10; // set TMOD to mode 1.
|
||||||
|
TH1 = 0xFC; // 1ms timer.
|
||||||
|
TL1 = 0x18;
|
||||||
|
ET1 = 1; // enable timer 1 interrupt.
|
||||||
|
EA = 1; // enable global interrupt.
|
||||||
|
TR1 = 1; // start timer 1.
|
||||||
|
}
|
||||||
|
|
||||||
|
// timer1 interrupt service routine.
|
||||||
|
void timer1ISR(void) interrupt 3
|
||||||
|
{
|
||||||
|
TH1 = 0xFC; // reset timer.
|
||||||
|
TL1 = 0x18;
|
||||||
|
|
||||||
|
// display the number.
|
||||||
|
set38Transistors(i);
|
||||||
|
P2 = LedBuff[i];
|
||||||
|
i = (i + 1) % 6; // to switch to the next digit.
|
||||||
|
|
||||||
|
// 1s timer.
|
||||||
|
if (++cnt >= 1000) { // if reached 1s.
|
||||||
|
cnt = 0;
|
||||||
|
if (display_time > 0) {
|
||||||
|
display_time--; // decrease the time.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test4()
|
||||||
|
{
|
||||||
|
initTimer();
|
||||||
|
while (1) {
|
||||||
|
// split the time into 6 digits.
|
||||||
|
unsigned char first_digit = display_time / 100000; // to get the first digit.
|
||||||
|
unsigned char second_digit = (display_time % 100000) / 10000; // to get the second digit.
|
||||||
|
unsigned char third_digit = (display_time % 10000) / 1000; // to get the third digit.
|
||||||
|
unsigned char fourth_digit = (display_time % 1000) / 100; // to get the fourth digit.
|
||||||
|
unsigned char fifth_digit = (display_time % 100) / 10; // to get the fifth digit.
|
||||||
|
unsigned char sixth_digit = display_time % 10; // to get the sixth digit.
|
||||||
|
|
||||||
|
// load the number in the buffer.
|
||||||
|
// 5 is high digit.
|
||||||
|
// 0 is low digit.
|
||||||
|
LedBuff[5] = LedChar[first_digit]; // to display the first digit.
|
||||||
|
LedBuff[4] = LedChar[second_digit]; // to display the second digit.
|
||||||
|
LedBuff[3] = LedChar[third_digit]; // to display the third digit.
|
||||||
|
LedBuff[2] = LedChar[fourth_digit]; // to display the fourth digit.
|
||||||
|
LedBuff[1] = LedChar[fifth_digit]; // to display the fifth digit.
|
||||||
|
LedBuff[0] = LedChar[sixth_digit]; // to display the sixth digit.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
test4();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user