From 0e7cdd870b80de6c7fd39fd352f09f6a276ca75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E6=98=B4?= Date: Wed, 23 Apr 2025 10:45:36 +0800 Subject: [PATCH] archieve: homework5 header: basic functions --- homework5/src/homework5.h | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/homework5/src/homework5.h b/homework5/src/homework5.h index e69de29..3d9cd41 100644 --- a/homework5/src/homework5.h +++ b/homework5/src/homework5.h @@ -0,0 +1,40 @@ +// homework5.h +/* + * this header defines: + * 1. pin numbers to control the LED and the Seg. + * 2. the function to control the LED and the Seg. + * 3. the function to display the number on the Seg. + * 4. the function to set the 38 transistors. + */ + +#include + +// variables: +// pin numbers: +sbit BUS1A = P2 ^ 0; // BUS1A: BUS for the LED1(RED) and the Seg A. +sbit BUS2B = P2 ^ 1; // BUS2B: BUS for the LED2(ORANGE) and the Seg B. +sbit BUS3C = P2 ^ 2; // BUS3C: BUS for the LED3(YELLOW) and the Seg C. +sbit BUS4D = P2 ^ 3; // BUS4D: BUS for the LED4(GREEN) and the Seg D. +sbit BUS5E = P2 ^ 4; // BUS5E: BUS for the LED5(AQUA) and the Seg E. +sbit BUS6F = P2 ^ 5; // BUS6F: BUS for the LED6(BLUE) and the Seg F. +sbit BUS7G = P2 ^ 6; // BUS7G: BUS for the LED7(PURPLE) and the Seg G. +sbit BUS8DP = P2 ^ 7; // BUS8DP: BUS for the LED8(WHITE) and the Seg DP. +// 38 transistors controller: +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 + +// functions: +// 38 transistors controller: +void set38Transistors(unsigned char number) // set the 38 transistors. +{ + // turn on the 38 transistors: + ENLED = 0; + ADDR3 = 1; + // split the number into 3 binary numbers: + ADDR2 = (number & 0x04) >> 2; + ADDR1 = (number & 0x02) >> 1; + ADDR0 = (number & 0x01); +} \ No newline at end of file