Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include "Display_utils.h" unsigned int digit_no, digit10, digit1, digit ; void main() { PORTC = 0; // clear PORTA (make sure both displays are off) TRISC = 0; // designate PORTA pins as output PORTB = 0; // clear PORTD (make sure LEDs are off) TRISB = 0; // designate PORTD pins as output TRISA = 1; // designate PORTA pins as input do { digit = PORTA ; digit1 = digit % 10; digit10 = (digit / 10) % 10 ; PORTC = mask(digit1); // prepare ones digit PORTB = mask(digit10); // prepare tens digit } while (1); // endless loop }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 //-------------- Returns mask for common cathode 7-seg. display unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0x3F; case 1 : return 0x06; case 2 : return 0x5B; case 3 : return 0x4F; case 4 : return 0x66; case 5 : return 0x6D; case 6 : return 0x7D; case 7 : return 0x07; case 8 : return 0x7F; case 9 : return 0x6F; } //case end }//~
ADCON1 = 0x07;
thanks for your kind attentionI don't have the code but I will write and post the code in another 2 hours.
asm clrwdt
OPTION_REG = 0x87;
asm clrwdt
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 #define DIP_SWITCH (PORTA & 0x3F) #define SSD_DATA_PORT PORTB #define SSD_CONTROL_PORT PORTC const unsigned char cc_mask[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; unsigned char digit = 0, digits[2] = {0, 0}; //Timer1 //Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 2 ms //Place/Copy this part in declaration section void InitTimer1() { T1CON = 0x01; TMR1IF_bit = 0; TMR1H = 0xF8; TMR1L = 0x30; TMR1IE_bit = 1; INTCON = 0xC0; } void Interrupt() { if((TMR1IE_bit) && (TMR1IF_bit)) { //Enter your code here SSD_CONTROL_PORT = (SSD_CONTROL_PORT & 0xFC); switch(digit) { case 0: SSD_DATA_PORT = digits[0]; SSD_CONTROL_PORT = (SSD_CONTROL_PORT & 0xFC) | 0x01; break; case 1: SSD_DATA_PORT = digits[1]; SSD_CONTROL_PORT = (SSD_CONTROL_PORT & 0xFC) | 0x02; break; }; if(++digit > 1) { digit = 0; } TMR1IF_bit = 0; TMR1H = 0xF8; TMR1L = 0x30; } } void main() { asm clrwdt OPTION_REG = 0x87; CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xFF; TRISB = 0x00; TRISC = 0x00; InitTimer1(); while(1) { asm clrwdt digits[0] = cc_mask[(PORTA & 0x3F) / 10]; digits[1] = cc_mask[(PORTA & 0x3F) % 10]; } }
digits[0] = cc_mask[(PORTA & 0x3F) / 10];
digits[1] = cc_mask[(PORTA & 0x3F) % 10];
digits[0] = cc_mask[DIP_SWITCH / 10];
digits[1] = cc_mask[DIP_SWITCH % 10];
This is the new circuit I designed for your project. I will post the code soon.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?