A buzzer finds application in quizzing, where the quiz master must know exactly who presses the first button to answer the question.Instead of glowing the bulb corresponding to the person who presses the button first, we can show the number corresponding to the person in a 7 segment display.This is desirable since its simple and less power consuming than lighting a bulb.We can simply program the PIC 18f4550 using USB cable connected to the system. No need for any programmer arrangement if we have already programmed the boot loader into the device. We need the PICDEM FS USB tool available in Microchip's site.This tool helps us to program the device using USB cable. Another tool called C-18 needs to to installed on the system along with the mplab ide to develop the software for the project .
#include "usart.h"
extern void _startup (void);
// See c018i.c in your C18 compiler directory
#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
#define byte unsigned char
void delay (void);
void display(byte);
void main(void)
{
byte c=0;
TRISD = 0;
TRISB = 255;
while(1)
{
c= ~PORTB;
switch (c)
{
case 1:
display(0);
break;
case 2:
display(1);
break;
case 4:
display(2);
break;
case 8:
display(3);
break;
case 16:
display(4);
break;
case 32:
display(5);
break;
case 64:
display(6);
break;
case 128:
display(7);
break;
default:
display(10);
break;
}
delay();
if(c)
{
while(1);
}
//the while loop resets to start of main if reset is done pin 1 gnded (hardware reset)
}
}
void delay(void)
{
long int count = 200000;
while (count--)
{
}
}
void display(byte a)
{
switch(a)
{// these may or maynot work on all 7 segments to determine which segment is which we need to write test programs
case 0: PORTD = 0b01000000;break;
case 1: PORTD = 0b11111010;break;
case 2: PORTD = 0b00100100;break;
case 3: PORTD = 0b00110000;break;
case 4: PORTD = 0b10010010;break;
case 5: PORTD = 0b00010001;break;
case 6: PORTD = 0b00000001;break;
case 7: PORTD = 0b11111000;break;
case 8: PORTD = 0b00000000;break;
case 9: PORTD = 0b10010000;break;
case 10: PORTD = 0b11111111;break;
default :
PORTD = 0b11111111;
break;
}
}
PORTD is used as the output port ,ie the seven segment display to display the number corresponding to the pressed pin on PORTB.PORTB is normally connected to VCC through a pullup (10k). Each pin is gnded to detect a key press .A switch is connected between the pin and the gnd.The ckt detects the first key pressed among 8 keys and displays the keynumber on seven segment.
No comments:
Post a Comment