archieve: homework6 header

This commit is contained in:
2025-05-06 12:57:17 +08:00
parent 7ddc888862
commit c8709b51af
+67
View File
@@ -1 +1,68 @@
// homework6.h
/*
* this is the header file to
* define the
* variables:
* - pins for the LEDs and the segs
* - pins for the 38 transistors
* - seg chars to display to display the number
* functions:
* - set the 38 transistors.
*/
#include <REG52.H>
// variables:
// pins for the LEDs and the segs
sbit BUS1A = P2 ^ 0; // Red LED and A Seg
sbit BUS2B = P2 ^ 1; // Orange LED and B Seg
sbit BUS3C = P2 ^ 2; // Yellow LED and C Seg
sbit BUS4D = P2 ^ 3; // Green LED and D Seg
sbit BUS5E = P2 ^ 4; // Aqua LED and E Seg
sbit BUS6F = P2 ^ 5; // BLUE LED and F Seg
sbit BUS7G = P2 ^ 6; // Purple LED and G Seg
sbit BUS8DP = P2 ^ 7; // White LED and DP Seg
// pins for the 38 transistors
sbit ADDR0 = P1 ^ 0; // to A(A0)
sbit ADDR1 = P1 ^ 1; // to B(A1)
sbit ADDR2 = P1 ^ 2; // to C(A2)
sbit ADDR3 = P1 ^ 3; // to E1
sbit ENLED = P1 ^ 4; // to E2 & E3
// seg chars to display to display the number
unsigned char code LedChar[] = {
0xC0,
0xF9,
0XA4,
0XB0,
0X99,
0X92,
0X82,
0XF8,
0X80,
0X90,
0X88,
0X83,
0XC6,
0XA1,
0X86,
0X8E,
};
// functions:
// 38 transistors control function
/*
* param:
* - addr: the address of the 38 transistors.
* function:
* - Convert the address to 3 binary numbers.
* - Set the 38 transistors to the address.
*/
void set38(unsigned char addr)
{
// Enable the 38 transistors.
ENLED = 0;
ADDR3 = 1;
// Set the 38 transistors to the address.
ADDR0 = addr & 0x01;
ADDR1 = (addr & 0x02) >> 1;
ADDR2 = (addr & 0x04) >> 2;
}