Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F873A code help

Status
Not open for further replies.

jbmartin87

New Member
Hi, guys. I'm an electronic engineering technology student in my final year. It was reccomended to me to use a PIC16F873A (which I now have) for my final project. I need a little help to get started. I've been reading many sites for the past few days and still don't know where to start.

I have some experience with both assembly and c languages. I am currenly working with mikroC and mplab ide. Would prefer to use C.

What I am trying to accomplish: read in 3 digital values from Port C (RC0, RC1, RC2) (port c because of its ST property) and based on some IF statements output a digital value on Port A (RA0).

Also: Can I assign the ports to variables to make working with my IF statements easier?

All help is greatly appreciated! If you need me to clarify anything just ask. Thanks in advance.
 
Hi, JB Martin

IF you really use the Mikro C compiler ... and are supposed to become an engineer.

You MUST have known four things :

1) the HELP tab : most right place in the upper toolbar ...

2) the example folder located here: C:\Program Files\Mikroelektronika\MikroC\Example ... on your HDD

3) The MkE Forums here : mikroElektronika • Index page

4) the MikroE free online books : Books | mikroElektronika


AND Overall ...

THE HOLY MANUAL : https://www.electro-tech-online.com/custompdfs/2010/03/mikroc_manual.pdf

You'll find there much more than all you want to know ...



and remember the '873 is very similar to the '877 ...

Alain
 
Last edited:
Ok... started to write my code. Bare with me, as I am taking baby steps.

Here's what I have:
Code:
void main() {
  PORTB = 0x00; //initialize portb
  PORTC = 0x00; //initialize portc
  TRISB = 0x00; //set portb as output
  TRISC = 0xFF; //set portc as input

  do {
    if(PORTC=0x01) PORTB = 0xFF; //set portb to 0xFF if portc is 0x01
  } while (1); //endless loop
}

When I run it in mikroC software emulator my if statement sets portc to 0x01 which in turn sets portb to 0xff.
What have I done wrong?

Thanks.
 
If you use only one equal sign, 0x01 is placed to PORTC. Using two equal signs makes it comparison operator.
So I think that should be like this: if (PORTC == 0x01) PORTB = 0xFF;
 
you need == (2 ='s as they are a comparator)

= <- assignment
== <- comparator

Edit: Laamane beat me to it lol
 
Last edited:
ohhh... thanks guys.

I should have known that, but I've been doing alot of work with visual basic lately.
 
Last edited:
ohhh... thanks guys.

I should have known that, but I've been doing a lot of work with visual basic lately.

Visual Basic is a great language (VB6 is anyway), it's a shame C has to have two different operators when VB can get away just fine with one.
 
Need a little help again....

I wrote a simple little program to make all portB output a high value. Tested it in PIC simulator IDE and it works. Next I try programming/burning the chip using USB PIC PRG.

I put the chip in the breadboard and make the following connections: Vdd(Pin 20) = +5V, Vss(Pins 8,19) = Gnd, and Vpp(Pin 1) = +5V. But I am not getting any output on portB. Any ideas on what I am doing wrong?

**broken link removed**
 
If you didn't specify a clock source it'll use the internal oscillator. But post your program code so we can see the entire situation.
 
Visual Basic is a great language (VB6 is anyway), it's a shame C has to have two different operators when VB can get away just fine with one.

That's because "if (a=b)" is valid and has a different meaning from "if (a==b)". Parsing a string for example: "while (c=str[i++])" will terminate when c==0.
 
k, new question....

If I want to set RB0 high, I can use: PORTB = 0x01

Is there a way to just 'address' that pin? For example RB0 = 1 (I know that doesn't work, but that's the best way I can explain myself)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top