Electronics > Beginners
PIC16F690 in C language beginner
ElectroElvis:
Hello evryone,
I have recently got my PickKit 2 Demo board with PIC16F690 microcontroller. Since I have just begun with it and with reading book C What happens I found one simple problem I cannot get over it. I
I hope that this is right forum subsection for this sort of things regarding electornics.
My problem is very simple, I have 4 LED on port C pins 0, 1, 2, 3 and I would like to turn them on all at same time and turn them off (BLINK), I have tried with this two options:
1. void main()
{
PORTC = 0;
TRISC = 0;
while(1)
{
PORTC = 1;
Delay_ms(1000);
PORTC = 0;
Delay_ms(1000);
}
}
At this option only 1 led is turning on and off and this is on pin C0, have no clue why not all of them.
2. void main()
{
PORTC = 0;
TRISC = 0;
while(1)
{
PORTC = ~PORTC;
Delay_ms(1000);
}
}
Here all four leds turn on and stay constantly on. What I am doing wrong here?
Beside that, half of declarations I try to use are either not there or missing. So If I try to just copy from book or any other tutorial I still get errors.
For example: SET_OUTPUT_B(), GPB, INPUT_B(), SET_TRIS_B(),... evrything is not recognizeable, any reasons why?
darrylp:
Hint, look at 1 in binary, then go see how the ports of C are mapped to each binary position.
To turn four on its binary 00001111 or 15 decimal. written to the port address of C.
Sent from my HTC One X using Tapatalk 2
ElectroElvis:
@darrylp, thanks for tip, but I have no clue where or what to search. I do know what binary is, but I have just looked PIC16F690 documentation for PORTC relation and could't find a thing related to binary values of particular port.
Can you somehow enlighten me please sinec I am just trying to learn from beginning. And the book I have bought it is damn useless since anything I type it mostly does not work.
notsob:
have a read of the PIC tutorials at pcbheaven.com - not in C but you will get a good idea about how a PIC works and learn a bit in regards to PORTs
IanB:
To turn the 4 LEDs on I think you could write:
PORTC = 15;
To turn the 4 LEDs off write:
PORTC = 0;
(Note, I know nothing about programming PICs, but from what I read here you have to set bits in PORTC corresponding to the outputs. So to turn on the first four outputs of PORTC you have to send 00001111 binary to the port--a "1" for each output--and 00001111 binary is 15 decimal.)
Navigation
[0] Message Index
[#] Next page
Go to full version