Author Topic: PIC16F690 in C language beginner  (Read 10000 times)

0 Members and 1 Guest are viewing this topic.

Offline ElectroElvisTopic starter

  • Regular Contributor
  • *
  • Posts: 61
  • Country: at
  • http://electroelvis.com/
    • ElectroElvisBlog
PIC16F690 in C language beginner
« on: December 01, 2012, 10:04:06 pm »
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?


     
« Last Edit: December 01, 2012, 10:45:33 pm by ElectroElvis »
 

Offline darrylp

  • Regular Contributor
  • *
  • Posts: 127
  • Country: gb
Re: PIC16F690 in C language beginner
« Reply #1 on: December 01, 2012, 10:45:15 pm »
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

 

Offline ElectroElvisTopic starter

  • Regular Contributor
  • *
  • Posts: 61
  • Country: at
  • http://electroelvis.com/
    • ElectroElvisBlog
Re: PIC16F690 in C language beginner
« Reply #2 on: December 01, 2012, 10:54:09 pm »
@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.

Offline notsob

  • Frequent Contributor
  • **
  • Posts: 696
  • Country: au
Re: PIC16F690 in C language beginner
« Reply #3 on: December 01, 2012, 10:56:29 pm »
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
« Last Edit: December 01, 2012, 10:58:09 pm by notsob »
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11885
  • Country: us
Re: PIC16F690 in C language beginner
« Reply #4 on: December 01, 2012, 11:07:29 pm »
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.)
 

Offline ElectroElvisTopic starter

  • Regular Contributor
  • *
  • Posts: 61
  • Country: at
  • http://electroelvis.com/
    • ElectroElvisBlog
Re: PIC16F690 in C language beginner
« Reply #5 on: December 01, 2012, 11:13:28 pm »
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.)

You are right mate, thanks for posting that. It looks like I need some sleep since its late for thinking.

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: PIC16F690 in C language beginner
« Reply #6 on: December 02, 2012, 01:18:48 am »
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
 

Offline mark5009

  • Contributor
  • Posts: 25
Re: PIC16F690 in C language beginner
« Reply #7 on: December 02, 2012, 06:33:50 am »
Elvis,

Given that you seem to be a novice at this stuff, my suggestion would be that you have a look at the JAL[1] 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

  .. mark


[1] http://justanotherlanguage.org/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf