0% found this document useful (0 votes)
6 views

Code Pic

The document contains code for a microcontroller to control a 7-segment display. It defines pins for the display segments and a pulse counting function. The main loop displays the pulse rate on the 7-segment display when a button is pressed and counts pulses for 1 second.

Uploaded by

Montaha Alduais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Code Pic

The document contains code for a microcontroller to control a 7-segment display. It defines pins for the display segments and a pulse counting function. The main loop displays the pulse rate on the 7-segment display when a button is pressed and counts pulses for 1 second.

Uploaded by

Montaha Alduais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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 DD3_Set at RB6_bit; // New segment pin
sbit start at RB7_bit;

unsigned short j, DD0, DD1, DD2, DD3; // Updated variable


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; // 192
case 1 : return 0xF9; // 249
case 2 : return 0xA4; // 164
case 3 : return 0xB0; // 176
case 4 : return 0x99; // 153
case 5 : return 0x92; // 146
case 6 : return 0x82; // 130
case 7 : return 0xF8; // 248
case 8 : return 0x80; // 128
case 9 : return 0x90; // 144
} // 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) % 10;
DD2 = mask(DD2);
DD3 = pulserate / 1000;
DD3 = mask(DD3);

for (i = 0; i <= 180 * j; i++) {


DD0_Set = 0;
DD1_Set = 1;
DD2_Set = 1;
DD3_Set = 1; // New segment control
PORTB = DD0;
delay_refresh();
DD0_Set = 1;
DD1_Set = 0;
DD2_Set = 1;
DD3_Set = 1; // New segment control
PORTB = DD1;
delay_refresh();
DD0_Set = 1;
DD1_Set = 1;
DD2_Set = 0;
DD3_Set = 1; // New segment control
PORTB = DD2;
delay_refresh();
DD0_Set = 1;
DD1_Set = 1;
DD2_Set = 1;
DD3_Set = 0; // New segment control
PORTB = DD3;
delay_refresh();
}

DD3_Set = 1;
}

void main() {
CMCON = 0x07; // Disable Comparators
TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P only
TRISB = 0b11000000; // RB7 and RB6 inputs, rest output
OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 for counter mode
pulserate = 0;
j = 1;
display();

do {
if (!start) {
delay_debounce();
countpulse();
j = 4;
display();
}
} while (1); // Infinite loop
}

You might also like