50 likes | 190 Views
My LED Functions. Scott Nichols. // A // --- // F| G |B // --- // E| |C // ---.Dp // D //. // a zero means LED ON DpGFE DCBA // #define NUM1 0xF9 //0b1111 1001 #define NUM2 0xA4 //0b1010 0100 #define NUM3 0xB0 //0b1011 0000 #define NUM4 0x99 //0b1001 1001
E N D
My LED Functions Scott Nichols // A // --- // F| G |B // --- // E| |C // ---.Dp // D //
// a zero means LED ON DpGFE DCBA // #defineNUM1 0xF9//0b1111 1001 #defineNUM2 0xA4//0b1010 0100 #defineNUM3 0xB0//0b1011 0000 #defineNUM4 0x99//0b1001 1001 #defineNUM5 0x92//0b1001 0010 #defineNUM6 0x82//0b1000 0010 #defineNUM7 0xF8//0b1111 1000 #defineNUM8 0x80//0b1000 0000 #defineNUM9 0x90//0b1001 0000 #defineNUM0 0xC0//0b1100 0000 #defineNUMA 0x88//0b1000 1000 #defineNUMB 0x83//0b1000 0011 #defineNUMC 0xA7//0b1010 0111 #defineNUMD 0xA1//0b1010 0001 #defineNUME 0x86//0b1000 0110 #defineNUMF 0x8E//0b1000 1110 #defineBLANK 0xFF #defineNUMERROR 0x86//0b1000 0110
voidshowNumber(unsigned long outputNum) { switch(outputNum) { case0: PORTA=NUM0; break; case1: PORTA=NUM1; break; ... case10: PORTA=NUMA; break; ... caseBLANK: PORTA=BLANK; break; default: PORTA=NUMERROR; } }
// Defines for the segments // #definePORTB_LED_SEG 0x0F #defineLED_SEG_3 0xE0//0b1110 #defineLED_SEG_2 0xD0//0b1101 #defineLED_SEG_1 0xB0//0b1011 #defineLED_SEG_0 0x70//0b0111 #defineLED_SEG_D 0xF0//0b1111
voidshowLED(unsignedchar ledshow) { unsigned char pB; pB = PORTB; showNumber(BLANK);// ghosting if not here switch(ledshow) { case 3: PORTB =(pB & PORTB_LED_SEG)| LED_SEG_3; break; case 2: PORTB =(pB & PORTB_LED_SEG)| LED_SEG_2; break; case 1: PORTB = (pB & PORTB_LED_SEG) | LED_SEG_1; break; case 0: PORTB = (pB & PORTB_LED_SEG) | LED_SEG_0; break; default: PORTB = (pB & PORTB_LED_SEG) | LED_SEG_D; } }