archieve: homework5 header: basic functions
This commit is contained in:
@@ -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 <REG52.H>
|
||||
|
||||
// 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);
|
||||
}
|
||||
Reference in New Issue
Block a user