Help My Project(12CH LED Driver)??
- SemiconductorCat
- Major
- Posts: 455
- Joined: Mon Aug 22, 2011 8:42 pm
- Location: currently in hyperspace
Re: Help My Project(12CH LED Driver)??
what's the magic of it?
Just simply press the assembly listing button and generate the assembly listing and review through it.
Simply it will be placed by a macro or a library function.
Nothing magic is there. Keep digging it.
Just simply press the assembly listing button and generate the assembly listing and review through it.
Simply it will be placed by a macro or a library function.
Nothing magic is there. Keep digging it.
Re: Help My Project(12CH LED Driver)??
Okay, will try my best. Only thing is I didn't use any of Mikroe compilers. So I'm not familiar with library calls, etc... I'm used to write everything by my own so I have full control over my codeTill,I download HI-TECH C,please help me for Mikro C

Okay... So when you are running with microcontrollers, using sawtooth method to variate timer is not needed. You have stated that you use PIC16F877A and according to my memory this uC has many ADC pins.
Simply connect a variable resistor to a ADC pin, power one side of variable resistor to 5V and the other side to ground so the pin get varies from 5V to 0. Within your code, you need to first define the port to be ADC (Since it is multiplexed with a GPIO port) and then read the ADC pin (refer ADC_Read function). If my memory is right, 16F877A has 10-bit resolution. That means you get the 0 to 5V variance as an integer between 0 and 1023. You can convert it to voltage using (5 / 1023 x input_value) formula. But you can directly use the digital number between 0 to 1023 to control the LED sequence.
If you max speed is delay = 100ms and slowest is 1000ms, you can map 0 to 1023 digital value for this. Simple formula is,
(1023 - 0) / (1000 - 100) = (1023 - 0) / (900) = 1.137
If your input is input_value, then time duration is given by,
time_delay = (input_value x 1.137) + 100
Note: +100 is there since your minimum speed is 100ms.
I hope you can continue from here. Good luck!
Please shift to HI-TECH C soon. It would be advantageous for both of us

- SemiconductorCat
- Major
- Posts: 455
- Joined: Mon Aug 22, 2011 8:42 pm
- Location: currently in hyperspace
Re: Help My Project(12CH LED Driver)??
But the problem is PIC16XXXX things does not have a FPU. So how could you do the calculation?
The compiler will assemble multiplication with heavy library calls. You could simply use the SevenZero's
multiplication method with no trouble. But it will increase the code size. So how to fix that without that
overhead?
Well that's where you need some experience , [ reading other's code will fix this,believe me, read as you could].
For this I'll give you a simple method.
You could use the MSB [most significant ] 4 bits of ADC,and
read that value to a variable and then call a lookup table using that value.Lookup table function will
return with a value of the right delay,so you could call delay() with it.
Here is a simple lookup table code example:
https://robot.lk/viewtopic.php?f=92&t=3307
Unfortunately it was on assembly, but you could do this with a simple switch or array using MicroC.
if you can't figure out this then just google "microc"+"lookuptable"
Please don't forget to review the assembly listings too. That will increase your knowledge in compilers
and also in embedded at the same time.
The compiler will assemble multiplication with heavy library calls. You could simply use the SevenZero's
multiplication method with no trouble. But it will increase the code size. So how to fix that without that
overhead?
Well that's where you need some experience , [ reading other's code will fix this,believe me, read as you could].
For this I'll give you a simple method.
You could use the MSB [most significant ] 4 bits of ADC,and
read that value to a variable and then call a lookup table using that value.Lookup table function will
return with a value of the right delay,so you could call delay() with it.
Here is a simple lookup table code example:
https://robot.lk/viewtopic.php?f=92&t=3307
Unfortunately it was on assembly, but you could do this with a simple switch or array using MicroC.
if you can't figure out this then just google "microc"+"lookuptable"
Please don't forget to review the assembly listings too. That will increase your knowledge in compilers
and also in embedded at the same time.
Re: Help My Project(12CH LED Driver)??
That calculation is simply nothing on 16F877. However when it is complicated such as Fourier transformations, etc... it is helpful to use lookup tables. (However, it is a tradeoff between using lookup tables and improved Fourier methods such as Fast Fourier Transformation (FFT) on fixed point processors.. If memory fetches are faster, lookup tables will be good, if slower FFT will be good).
However I can suggest another nice solution. The dsPICs. These have a built-in FPU. Those are called Digital Signal Controllers (or poor man's DSP). If you take dsPIC 30F4011 processor, that's kind of a fantastic processor with single cycle floating point divisions.
Nandika, we can come to those step by step. Also, good to know the ASM codes too as Sem.. suggested. But it is not very urgent for now. Just concentrate on learning theory of electronics in combinations to programming with microcontrollers.
However I can suggest another nice solution. The dsPICs. These have a built-in FPU. Those are called Digital Signal Controllers (or poor man's DSP). If you take dsPIC 30F4011 processor, that's kind of a fantastic processor with single cycle floating point divisions.
Nandika, we can come to those step by step. Also, good to know the ASM codes too as Sem.. suggested. But it is not very urgent for now. Just concentrate on learning theory of electronics in combinations to programming with microcontrollers.
Re: Help My Project(12CH LED Driver)??
Can't we do that by using a V/R as the resistor of RC Osscilator?
[ Post made via Mobile Device ]
[ Post made via Mobile Device ]

Re: Help My Project(12CH LED Driver)??
Nandika,
https://robot.lk/viewtopic.php?f=18&t=2960 this is a very beautiful one for your project. But it uses some complex ASM codes and you'll unable to understand (I'm too
).
But if you want to learn ASM, you'll can do it. Anyway you don't want any ASM knowladge to use this code. you can make any charsing method by using this code.
*By the way, your own coding will increase your knowladge.
[ Post made via Mobile Device ]
https://robot.lk/viewtopic.php?f=18&t=2960 this is a very beautiful one for your project. But it uses some complex ASM codes and you'll unable to understand (I'm too

But if you want to learn ASM, you'll can do it. Anyway you don't want any ASM knowladge to use this code. you can make any charsing method by using this code.
*By the way, your own coding will increase your knowladge.
[ Post made via Mobile Device ]

- SemiconductorCat
- Major
- Posts: 455
- Joined: Mon Aug 22, 2011 8:42 pm
- Location: currently in hyperspace
Re: Help My Project(12CH LED Driver)??
After all , the project that posted by Rksk is a good one. That's the reason we should start reading it's
code in advance.
Just take a copy of the manual of your assembler and CHIP and then start reading the source code. Whenever
you met something ambiguous feel free to refer to the manual. Don't try to memorize the manuals. It will
transfer to your brain automatically when your using it. Just like using a washing machine.If ambiguity still
not sloved then do google or ask it in robot.lk/newsgroup or IRC.
Just ignore this sentence,
that project posted by Riksk is good for reading.
--SemiconductorCat--
code in advance.
Just take a copy of the manual of your assembler and CHIP and then start reading the source code. Whenever
you met something ambiguous feel free to refer to the manual. Don't try to memorize the manuals. It will
transfer to your brain automatically when your using it. Just like using a washing machine.If ambiguity still
not sloved then do google or ask it in robot.lk/newsgroup or IRC.
Just ignore this sentence,
There is no magic way of creating things without reading line by line, checking it wire by wire.AfterallBut it uses some complex ASM codes and you'll unable to understand (I'm too ).
that project posted by Riksk is good for reading.
--SemiconductorCat--
Re: Help My Project(12CH LED Driver)??
Thanks ZevenZero,SemiconductorCat and others,
I have problems about ADC unit of PIC16F877A.
What are ADCON0 bit6,7?please,explain me? And,this what is this result formats?
And,
This code work well.
I want to change analog input channel.i dcded like this,
But,No change..
I connected variable resistor to channel2.turn off all LED.
I connected it again to channel1,it work well.(PROTEUS give some warning )
please,tell me about analog channel changing.
Thanks
I have problems about ADC unit of PIC16F877A.
What are ADCON0 bit6,7?please,explain me? And,this what is this result formats?
And,
This code work well.

Code: Select all
int temp_res;
void main() {
//"Right justified result format"??? enable -->bit7=1
//set all PORTA channel as analog input -->bit0-bit3=0000
//binary value of ADCON1 = 10000000 = hex value=80
ADCON1=0x80;
TRISA = 0xff; //PORTA INPUT
TRISB = 0x00; //PORTB OUTPUT
TRISC=0X00; //PORTC OUTPUT
do {
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTB
PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0
} while(1);
}
But,No change..
I connected variable resistor to channel2.turn off all LED.


I connected it again to channel1,it work well.(PROTEUS give some warning )
Code: Select all
int temp_res;
void main() {
//"A/D Conversion Clock Select bits"?? -->bit7-6=00
//Enable channel 2 -->bit5-3=010
//A/D Conversion Status bit -->bit2=1
//Nothing care-->bit1=0
//A/D On bit-->bit0=0
//binary value od ADCON0=00010100 = hex value=14
ADCON0=0x14;
//"Right justified result format"??? enable -->bit7=1
//set all PORTA channel as analog input -->bit0-bit3=0000
//binary value of ADCON1 = 10000000 = hex value=80
ADCON1=0x80;
TRISA = 0xff; //PORTA INPUT
TRISB = 0x00; //PORTB OUTPUT
TRISC=0X00; //PORTC OUTPUT
do {
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTB
PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0
} while(1);
}
Thanks
Re: Help My Project(12CH LED Driver)??
Thank you ZevenZero,
This calculation is good.but,i couldn't coding and simulate this.i will try today.

This calculation is good.but,i couldn't coding and simulate this.i will try today.
Actually,now downloading MPLAB-IDE with HI-TECH C....SevenZero wrote:
If you max speed is delay = 100ms and slowest is 1000ms, you can map 0 to 1023 digital value for this. Simple formula is,
(1023 - 0) / (1000 - 100) = (1023 - 0) / (900) = 1.137
If your input is input_value, then time duration is given by,
time_delay = (input_value x 1.137) + 100
Note: +100 is there since your minimum speed is 100ms.SevenZero wrote:I hope you can continue from here. Good luck!
Please shift to HI-TECH C soon. It would be advantageous for both of us![]()


- SemiconductorCat
- Major
- Posts: 455
- Joined: Mon Aug 22, 2011 8:42 pm
- Location: currently in hyperspace
Re: Help My Project(12CH LED Driver)??
There are only 4 registers that are related to the ADC unit.
refer to this: http://www.mikroe.com/eng/chapters/view ... g-modules/
refer to this: http://www.mikroe.com/eng/chapters/view ... g-modules/