hi , i am trying to learn pic programming and basic circuit. So i am unexperienced. I am using pic16f84a with 4 mhz crystal osillator. Circuit runs on 5 V with 7805 regulator. and this is the code:
include <16F84A.h>
define pir input(PIN_A2) // Switch on RA0
void main (void)
{
set_tris_a(0x11); set_tris_b(0x00); output_b(0x00);
while(1) { //Forever Loop
output_high(pin_B1);
output_high(pin_B2);
}
}
I import this file with pickit2.
There voltage supply on pic , i can read it with voltameter but somehow there is no output. It isnt work.
Anyone , any idea how to solve the problem ?
>>990430
Well that appears to be C or a variant of C. Every variant I've seen requires includes and defines to be preceded by a #. Have you tried doing #include #define and then recompiling?
>>990433
sorry my bad. Actually there is . The code is working. BEcause i tested it in simulation protheus 8.
Here is the correct version of the code
#include <16F84A.h>
#define pir input(PIN_A2) // Switch on RA0
void main (void)
{
set_tris_a(0x11);
set_tris_b(0x00);
output_b(0x00);
while(1) { //Forever Loop
output_high(pin_B1);
output_high(pin_B2);
}
}
>>990435
Oh ok, So all I see this doing is setting pins b1 and b2 to high forever. You have labeled pir input on pin a2, which I assume means you are trying to use a passive infrared sensor to trigger events on pins b1 and b2. Is this correct?
>>990435
>>990457
just to speed things up, Ill go ahead and say if you are trying to do actions based off of a input form pin a2, in the while(1) loop, you need to check the state of pir on a2 like this:
while(1){
if_high(pin_a2){
output_high(pin_B1);
output_high(pin_B2);
}
else{
output_low(pin_B1);
output_low(pin_B2);
}
}
also I dont know shit about pics, so double check that you have the pins set to output and input correctly.
>>990430
This is a backwards looking setup, the define makes it look like you're compiling for arduino or some shit.
What environment are you using?
Are you writing it in Proteus or in some other environment and then loading the hex file into Proteus to simulate it?
Have you pulled the mclr (reset) pin high? Have you set your configuration bits properly (oscillator, watchdog etc.)?
try while(true) rather than while(1)
>>990518
true is defined as 1.
>>990462
>>990460
i have compiled everythnig. The program is just for debug. To test the circuit. ORiginally as you presume there is also a pir . BUt to test the circuit if it is work correctly i delted it to only light the leds forever. But thin gis . LEds dont light up. And i have no idea why .
I check the voltage with multimeter. And it is 5 Volts supplying as it should. So where could be a problem i dont know
I am unexperienced on electornics. So i dont know hot to pull the mclr pin high. Is it something i should add to the code or someting that i should enable while a write down to the pic ( btw i using pickit2 to write the hex to the pic.) And also ı dont know hot to set the configuration bits also . How should i set them ?
>>990809
Physically connect MCLR to your +5V supply.
Are you using MPLAB?
>>990812
i connect 5V supply with 10k resistor already to MCLR pin. i dont use MPLAB , i am using Pic C Compiler.
>>990818
and protheus to simulate it
You need to see the datasheet of the pic16f84a at I/O ports.
TRISA.RA1=1; // is use to put ra1 as an input and =0 To put it like an output.
PORTB.RB0=1;// is to read/write on rb0 pin. depend if it has been set as an input/output
You can use [code [/code] to keep the spacing and indentation on this board, right? (the front [code is missing the ]
>>990818
>Pic C Compiler.
need more detail
Show the generated ASM, otherwise we're just guessing at what the various macros do.
E.g. TRISA and TRISB are in bank 1, so unless the macros explicitly select bank 1 by setting bit 5 (RP0) of the STATUS register, the assignments won't work.
FWIW, I don't recommend trying to program the PIC 10,12 or 16 series in C. It's easier to just write asm than than to spend your time looking at compiler-generated asm (which you need to do if you want your code to work).