Jerry John
Newbie level 1
- Joined
- May 3, 2014
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 29
SEVEN SEGMENT:
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 sbit IR_Tx at RA3_bit; sbit DD0_Set at RA2_bit; sbit DD1_Set at RA1_bit; sbit DD2_Set at RA0_bit; sbit start at RB7_bit; unsigned short j, DD0, DD1, DD2, DD3; unsigned short pulserate, pulsecount; unsigned int i; //-------------- Function to Return mask for common anode 7-seg. display unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0xC0; case 1 : return 0xF9; case 2 : return 0xA4; case 3 : return 0xB0; case 4 : return 0x99; case 5 : return 0x92; case 6 : return 0x82; case 7 : return 0xF8; case 8 : return 0x80; case 9 : return 0x90; } //case end } void delay_debounce(){ Delay_ms(300); } void delay_refresh(){ Delay_ms(5); } void countpulse(){ IR_Tx = 1; delay_debounce(); delay_debounce(); TMR0=0; Delay_ms(15000); // Delay 1 Sec IR_Tx = 0; pulsecount = TMR0; pulserate = pulsecount*4; } void display(){ DD0 = pulserate%10; DD0 = mask(DD0); DD1 = (pulserate/10)%10; DD1 = mask(DD1); DD2 = pulserate/100; DD2 = mask(DD2); for (i = 0; i<=180*j; i++) { DD0_Set = 0; DD1_Set = 1; DD2_Set = 1; PORTB = DD0; delay_refresh(); DD0_Set = 1; DD1_Set = 0; DD2_Set = 1; PORTB = DD1; delay_refresh(); DD0_Set = 1; DD1_Set = 1; DD2_Set = 0; PORTB = DD2; delay_refresh(); } DD2_Set = 1; } void main() { CMCON = 0x07; // Disable Comparators TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P only TRISB = 0b10000000; // RB7 input(start), rest output OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 for countermode(EBPD) pulserate = 0; j = 1; display(); do { if(!start){//penyongsang delay_debounce(); countpulse(); j= 3; display(); } } while(1); // Infinite loop } LCD: sbit IR_Tx at RA3_bit; sbit start at RB0_bit; unsigned short pulserate, pulsecount; sbit LCD_RS at RB2_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; void delay_debounce(){ Delay_ms(300); } void delay_refresh(){ Delay_ms(5); } void countpulse(){ IR_Tx = 1; delay_debounce(); delay_debounce(); TMR0=0; //0 to 1 transition Delay_ms(15000); // Delay 1 Sec IR_Tx = 0; pulsecount = TMR0; pulserate = pulsecount*4; } char message1[] = "Frequency= Hz"; char *freq = "000"; void Display_Freq() { freq[0] = (pulserate/100)%10+ 48; // Extract hundreds digit freq[1] = (pulserate/10)%10 + 48; // Extract tens digit freq[2] = pulserate%10 + 48; // Extract ones digit Lcd_Out(1, 11, freq); } void main() { CMCON = 0x07; // Disable Comparators TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P(clear) only TRISB = 0b00000001; // RB0 input(start),rest output,direction OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 counter mode pulserate=0; Display_Freq(); Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // CLEAR display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,message1); // Write message1 in 1st row do { if(!start){ delay_debounce(); countpulse(); Delay_ms(1000); // Delay 1 Sec Display_Freq();//TMR0@countpulse@pulsecount@pulserate,value } } while(1); // Infinite loop }
Last edited by a moderator: