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 void main() { TRISB = 0x00; // port B as output PORTB = 0x00; //clear portB while (1) { PORTD. RD1 = 1; PORTB = 0b1111001; //1 on 7 segment Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0100100; //2 on 7 segment Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0110000; //3 on 7 segment Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0011001; //4 Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0010010; //5 Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0000010; //6 Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b1111000; //7 Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0000000; //8 Delay_ms(1000); PORTD. RD1 = 1; PORTB = 0b0010000; //9 Delay_ms(1000); } }
while (1)
{
[B]write the code here to enable the display 1 and disable display 2[/B]
PORTB = display_digit[ my_number[0] ]
delay_ms(20)
[B]write the code here to enable the display 2 and disable display 1 [/B]
PORTB = display_digit[ my_number[1] ]
delay_ms(20)
}
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 char display_digit[9]= {0b1111001,0b0100100,0b0110000,0b0011001,0b0010010,0b0000010,0b1111000,0b0000000,0b0010000}; void main() { TRISD = 0x00; TRISB = 0x00; // port B as output PORTB = 0x00; //clear portB while (1) { PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[1]; //1 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[2]; //2 Delay_ms(20); PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[3]; //3 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[4]; //24 Delay_ms(20); PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[5]; //5 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[6]; //6 Delay_ms(20); PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[7]; //7 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[8]; //8 Delay_ms(20); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 char display_digit[9]= {0b1111001,0b0100100,0b0110000,0b0011001,0b0010010 ,0b0000010,0b1111000,0b0000000,0b0010000}; void main() { TRISD = 0x00; TRISB = 0x00; // port B as output PORTB = 0x00; //clear portB while (1) { PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[1]; //1 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[2]; //2 Delay_ms(20); } }
hi alex...
thanks for ur help mate.. im using common anode displays at RD0 and RD1 pins. i connected everything as on the link but still no result. the displays are blinking one after another. can u plz show me the way of using timer.. my code is below..
thanks
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 char display_digit[9]= {0b1111001,0b0100100,0b0110000,0b0011001,0b0010010,0b0000010,0b1111000,0b0000000,0b0010000}; void main() { TRISD = 0x00; TRISB = 0x00; // port B as output PORTB = 0x00; //clear portB while (1) { PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[1]; //1 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[2]; //2 Delay_ms(20); PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[3]; //3 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[4]; //24 Delay_ms(20); PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[5]; //5 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[6]; //6 Delay_ms(20); PORTD. RD0 = 1; //eneble segment 1 PORTD. RD1 = 0; //disable segment 2 PORTB = display_digit[7]; //7 Delay_ms(20); PORTD. RD0 = 0; PORTD. RD1 = 1; PORTB = display_digit[8]; //8 Delay_ms(20); } }
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 #include <16f877.h> #device PIC16F877 ADC=10 #fuses HS,WDT,PROTECT #use delay(clock=10000000) //----------------------------------------------------------------// #define digit_3 PIN_A1 #define digit_4 PIN_A2 //----------------------------------------------------------------// void init(void); //----------------------------------------------------------------// byte const seg_value[15] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92, 0x82,0xf8,0x80,0x90,0xff}; int16 time_value=0; int16 counter1=0; int8 digit1=0,digit2=0,count=1; //----------------------------------------------------------------// main() { port_b_pullups(TRUE); //----------------------------------------------------------------// init(); setup_wdt(WDT_2304MS); while(TRUE) { } } //----------------------------------------------------------------// void init(void) { set_tris_b(0x1f); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL); setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); set_timer1(0xF2Fb); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel( 0 ); } //**************************************************************** //*************************************************************** digit1=time_value/10; digit2=time_value-(digit1*10); //**************************************************************** } //----------------------------------------------------------------// #INT_TIMER1 void disp_isr() { set_timer1(0xf2fb); //Initialaize timer Ms output_d(0xff); switch(count) { case 1: output_bit(digit_3,0); output_bit(digit_4,1); output_c(seg_value[digit1]); count++; break; case 2: output_bit(digit_3,1); output_bit(digit_4,0); output_c(seg_value[digit2]); count=1; break; } //********************************************************************** counter1++; if(counter1==745) //1 sec { counter1=0; time_value++; } } else counter1=0; //******************************************************************
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?