#include "led_blnk.h"
#use fast_io(B)
// commenting & uncommenting this line shows 2 methods to do knight-rider
// using to slightly different methods
//#define _M1_
#ifdef _M1_
// this method doesn't work on Proteus but work ok with MPLAB & real hardware!!
#byte PORTB = 6
void main()
{
int1 d=0;
PORTB =1;
SET_TRIS_B( 0 );
for( ;; )
{
DELAY_MS(100);
if(d) PORTB >>=1;
else PORTB <<=1;
if(PORTB &0b10000001) d=~d;
}
}
#ELSE
// this method works on Proteus and with MPLAB & real hardware!!
void main()
{
int1 d=0;
int8 b=1;
SET_TRIS_B( 0 );
for( ;; )
{
output_b(b);
DELAY_MS(100);
if(d) b >>=1;
else b <<=1;
if(b &0b10000001) d=~d;
}
}
#ENDIF
I'm including everything in the following ZIP file.
Proteus wrongly excute the if(d) statement in the 1st method although it's ok!!!
This depends from read-modify-write logic of PIC micros and by d/a interface logic levels. You can solve the problem in two ways:
1. use resistors in series with leds.
2. edit the leds bar and change the Forward Voltage to 2.6V.
I'm sorry for you, but both work fine to me ! You must have something else that does not work
4.8V makes not sense (though it works, obviously, is unreasonable high forward voltage for a led). The led forward voltage is suffice to be greater than VUD voltage (and in fact 4.8V is greater!) but at more resonable real value.
Again, with analog (not digital!) 100 ohms resistor all is working fine.. and I used your circuit not the mine.
This problem will be solved without any need to change led voltage, though.