Helpful ReplyProgramming PIC 16F84A (I am Newbie)

Post
ramius123
New Member
2012/06/27 01:59:11
Hi, I have some questions on programming PIC 16F84A.
I am an Year 1 IT student and taking Basic Electronics subject.
 
My lecturer gave me an assignment for constructing a circuit and program the PIC with C language.
But, I never learn anything about C language... only learnt JAVA... T_T
 
This is the schematic diagram of the circuit.  (given by the lecturer)
p/s: correction, the ceramic capacitor 30uF change to 30pF...

 
1. LED lightning sequence: YELLOW, GREEN, RED and RED. 
2. Instruct the buzzer to turn ON and OFF with 250ms of delay on every change of LED colour from YELLOW to GREEN to RED to RED.
3. Provide 250ms as a delay to ON and OFF the LEDs. 
 
Below are the codes I tried but I dunno how to define the input.
Thanks!!!
 
 
 
#define        LED1        RB1_bit        //RED LED
#define        LED2        RB2_bit        //GREEN LED
#define        LED3        RB3_bit        //YELLOW LED
#define        LED4        RB4_bit        //RED LED
#define        BUZZER      RB6_bit         //Buzzer

void main(void) {     
 
TRISB = ????;             //set which pin as input?
 
while(1){               
LED3 = 1;               
delay_ms(250);               
LED3 = 0;               
delay_ms(250);               
BUZZER = 1;               
delay_ms(250);               
BUZZER = 0;               
delay_ms(250);               
LED2 = 1;               
delay_ms(250);               
LED2 = 0;               
delay_ms(250);               
BUZZER = 1;               
delay_ms(250);               
BUZZER = 0;               
delay_ms(250);               
LED4 = 1;               
delay_ms(250);               
LED4 = 0;               
delay_ms(250);               
BUZZER = 1;               
delay_ms(250);               
BUZZER = 0;               
delay_ms(250);               
LED1 = 1;               
delay_ms(250);               
LED1 = 0;               
delay_ms(250);               
BUZZER = 1;               
delay_ms(250);               
BUZZER = 0;               
delay_ms(250);       
}
}

 
post edited by ramius123 - 2012/06/27 02:00:31
leon_heller
Super Member
Re:Programming PIC 16F84A (I am Newbie) 2012/06/27 02:15:42
You should have current limiting resistors in series with the LEDs! You also need a decoupling capacitor across the supply pins.
post edited by leon_heller - 2012/06/27 02:17:36
JorgeF
Super Member
☄ Helpful
Re:Programming PIC 16F84A (I am Newbie) 2012/06/27 02:20:05
Hi
 
You are in the wrong forum.
This one is about electrical specs on programing the PIC chips using ICSP.
 
About your problem?
 
Input? Well maybe.
What I see is a push-button connected to the Master Clear (reset input of the PIC).
 
What is the purpose?
Use it as a Reset and have your code run from Power On Reset until the end of the sequence?
Disable the MCLR function and use PB3 as a generic input pin to have your code run from the push button action?
.................
 
After answering all those questions, to yourself, and geting the answers and/or decisions on that, some serious studying of the PIC datasheet is the next step ion order to know what the steps for each configuration and other details.
 
Anyhow, for total newbies, some studying of the tutorials on this site will provide a good ROI.
http://www.gooligum.com.au/
First review the Assembly tutorials in order to understand the inners of a PIC mcu.
Then go to the C tutorials to get aquainted with the specifics of programing for a mcu, rather than for a desktop computer.
 
 
Best regards
Jorge
 
ramius123
New Member
Re:Programming PIC 16F84A (I am Newbie) 2012/06/27 04:43:16
Sorry...
n
Thank you for your explanation n help.
 
The code should run after press the button n continue looping.
p/s: where is PB3?  (i cant find it.. swt...
 
The website really great!  Have so much of detailed tutorials Smile
JorgeF
Super Member
Re:Programming PIC 16F84A (I am Newbie) 2012/06/27 09:03:41
Hi
 
Sorry my mistake, PB3 is short for Port B pin 3, AKA RB3.
On most recent PICs, the MCLR function is shared with one input only pin.
But this old PIC doesn't have that feature.
So MCLR is simply MCLR.
 
One of the questions is already answered.
 
Best regards
Jorge
 
WaltR
Super Member
☄ Helpful
Re:Programming PIC 16F84A (I am Newbie) 2012/06/27 12:04:15
PB3 is short for Port B pin 3

Not quite. It is bit 3 of Port B, not pin 3 which is RA4. RB3 is on pin 9 of the PIC (for the DIP & SOIC packages). Look at the pin diagram (Table 1-1) in the data sheet.
You did download and read the data sheet, right?
 
Yep, Jorge was mistaken on MCLR. On the 16F84 it only has that one function. Later PICs allow the MCLR pin to be used as an input.
 
Still, the schematic you posted has many thing wrong. Are you sure this is exactly as your lecturer gave it to you? Or maybe the errors are on purpose to see if you read the data sheet to get this circuit to work. Therefore we'll point out the errors but not the solutions, that's up to you to learn.
 
1- The LED require current limiting resistors (as Leon pointed out).
2- The button on MCLR is not wired correctly to act as a reset button.
3- No de-coupling cap from Vdd to Vss. This to is required (again as Leon pointed out).
As to whether the code might work, use the MPLAB Simulator to Step through your code.  When you step through the code check that every register gets the value it should. This should always be to first step in debugging and will catch many 'dumb' errors.
 
Here is a good tutorial on using and programing PICs:
http://www.gooligum.com.au/tutorials.html