[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

hi , i am trying to learn pic programming and basic circuit.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 1

File: 28010-img_3538.jpg (33KB, 800x600px) Image search: [Google]
28010-img_3538.jpg
33KB, 800x600px
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 ]
>>
>>990809
leds blow up if you that allowed to have too much current, they almost always need a resistor on them.
have you checked to see if the leds are still good?

>>990899
I dont think so.
>>
>>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).
Thread posts: 17
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.