LED Runner
This is project that varies the speed of a running led on a PORT of a PIC16F877A microcontroller. The current running speed is determined by a potentiometer. Varying the output of the potentiometer, varies the speed of the running LED.
The source code that performs this action is bellow:
The code was written on MikroC PRO for PIC.
void my_delay(unsigned short mul){
unsigned int i;
for (i = 0; i< mul; i++){
delay_ms(50); //baseline delay
}
}
unsigned short mapADC(unsigned int adc_val){
return (unsigned short)(adc_val/ 50);
}
void runner(){
//runner code
portb = 1;
my_delay(mapADC(ADC_Read(0)));
portb = 2;
my_delay(mapADC(ADC_Read(0)));
portb = 4;
my_delay(mapADC(ADC_Read(0)));
portb = 8;
my_delay(mapADC(ADC_Read(0)));
portb = 16;
my_delay(mapADC(ADC_Read(0)));
portb = 32;
my_delay(mapADC(ADC_Read(0)));
portb = 64;
my_delay(mapADC(ADC_Read(0)));
portb = 128;
my_delay(mapADC(ADC_Read(0)));
}
void main() {
trisb = 0;
portb = 0;
while(1){
runner();
}
}
copy the code and paste in the code editor and compile.
wow! Nice Sir!. I will try that
ReplyDeleteThis comment has been removed by the author.
ReplyDeletei just tried it, and it worked as expected. thanks, for creating such a blog :-)
ReplyDelete