archieve: FinalTerm 51pins moudle

This commit is contained in:
2025-05-29 14:16:27 +08:00
parent fd0fd805b5
commit b13f90b5b4
4 changed files with 98 additions and 1 deletions
+3 -1
View File
@@ -18,7 +18,9 @@
},
"targets": {
"Debug": {
"excludeList": [],
"excludeList": [
"src/main.c"
],
"toolchain": "Keil_C51",
"compileConfig": {
"options": "null"
Binary file not shown.
+70
View File
@@ -0,0 +1,70 @@
/*
* @name: 51pins.h
* @author: msksbr
* @date: 2025-05-29
* @description: defines the 7 segs chars and pins for LEDs, 74HC138 and buttons
* @usage: #include "REG52.H"
*/
#include <REG52.H>
// 74HC138 pins (P1)
// controller pins
sbit ADDR0 = P1 ^ 0; // to A(A0)
sbit ADDR1 = P1 ^ 1; // to B(A1)
sbit ADDR2 = P1 ^ 2; // to C(A2)
// enable pins
sbit ADDR3 = P1 ^ 3; // to E1
sbit ENLED = P1 ^ 4; // to E2 & E3
// 7seg chars(P2)
unsigned char code seg7chars[] = {
0xFC, // 0: a b c d e f
0x60, // 1: b c
0xDA, // 2: a b g e d
0xF2, // 3: a b g c d
0x66, // 4: f g b c
0xB6, // 5: a f g c d
0xBE, // 6: a f g c d e
0xE0, // 7: a b c
0xFE, // 8: all segments
0xF6, // 9: a b c d f g
0xEE, // A: a b c e f g
0x3E, // B: c d e f g
0x9C, // C: a d e f
0x7A, // D: b c d e g
0x9E, // E: a d e f g
0x8E, // F: a e f g
0x02, // dp: decimal point
0x00, // all on
0xFF // blank: all off
};
// switch 74HC138
void switch138(unsigned char channel)
{
// @subsection: turn DEC channel to 3 BIN bits
bit A0 = channel & 0x01;
bit A1 = (channel >> 1) & 0x01;
bit A2 = (channel >> 2) & 0x01;
// @subsection: enable 74HC138
ADDR3 = 1;
ENLED = 0;
// @subsection: set 74HC138 pins
ADDR0 = A0;
ADDR1 = A1;
ADDR2 = A2;
}
// timer by ms based on timer0
void delay_ms(unsigned int ms)
{
TMOD = 0x01;
for (; ms > 0; ms--) {
TH0 = 0xFC;
TL0 = 0x66;
TR0 = 1;
while (!TF0);
TR0 = 0;
TF0 = 0;
}
}
+25
View File
@@ -0,0 +1,25 @@
/*
* @name: testPNP.c
* @author: msksbr
* @date: 2025-05-29
* @description: test PNP power supply.
*/
#include <REG52.H>
#include "../51pins/51pins.h"
unsigned char currentChannel = 0;
void main()
{
while (1) {
P2 = 0x00;
switch138(currentChannel);
if (currentChannel == 7) {
currentChannel = 0;
} else {
currentChannel++;
}
delay_ms(1);
}
}