PIC16F690 in C language beginner - Page 1
Forum section: electronics / beginners

author: ElectroElvis
author_rank: Regular Contributor
timestamp: December 01, 2012, 10:04:06 pm
content: 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. II 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?

author: darrylp
author_rank: Regular Contributor
timestamp: December 01, 2012, 10:45:15 pm
content: 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

author: ElectroElvis
author_rank: Regular Contributor
timestamp: December 01, 2012, 10:54:09 pm
content: @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.

author: notsob
author_rank: Frequent Contributor
timestamp: December 01, 2012, 10:56:29 pm
content: 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

author: IanB
author_rank: Super Contributor
timestamp: December 01, 2012, 11:07:29 pm
content: 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.)

author: ElectroElvis
author_rank: Regular Contributor
timestamp: December 01, 2012, 11:13:28 pm
content: Quote from: IanB on December 01, 2012, 11:07:29 pmYou are right mate, thanks for posting that. It looks like I need some sleep since its late for thinking.

author: AlfBaz
author_rank: Super Contributor
timestamp: December 02, 2012, 01:18:48 am
content: Nearly all pics have there I/O ports multiplexed with other peripherals. In this case PORTC seems to be shared with analog input and the default configuration is for them to be analog inputs. Try clearing the ANSEL and ANSELH registers to configure PORTC as digital IO as I think they are analog after a power on reset

author: mark5009
author_rank: Contributor
timestamp: December 02, 2012, 06:33:50 am
content: Elvis,Given that you seem to be a novice at this stuff, my suggestion would be that you have a look at the JAL language until you get your feet wet, as they say. JAP is free and will work on almost all PICs.Go through the tutorial. It will take you through the basics of using a PIC (setting the ports, port direction, etc.) in a very straightforward manner.Once you have an understanding of what the PIC can do, then taking the code into C is not such a big leap.Hope this helps.. markhttp://justanotherlanguage.org/