microcontroller coding
Now for reference i’l select PIC16F877A for coding
The PIN diagram is as shown below
Just look at the PINs. Let us start From number 1 . The first one is Memory clear and it must always be set high during operations. the next 7 pins say RAx. x range from 0 to 7 which gives you PORT “A” with 8 adressable pins. further down are REx with only 3 addressable pins(0,1,2). i guess you can now see PORTS A,B,C,D,E. the other pins are for supply and osc1 and osc 2 are pins that you must connect your crystalls accross.Hey ppl dont worry i will be dealing with hardware properly a bit later..
NOW START WITH INTIALIZATIONS
Start like you C program. The program below is the Led_bliking program that you have opened. now let me explain the code.
void main() {
PORTC = 0;
TRISC = 0;
while(1) { PORTC = ~PORTC;
Delay_ms(1000);
}
}
TRISC is the default register that tells if that port is input or output. now if set to “1″ it all acts as input and if set to “0″ all the eight bitgs in the port act as output ports.
So TRISA=0;TRISB=1;TRISC=0;TRISE=0 sets ports A,C,E asoutput ports and B as input port. got it??
PORTC = 0; is use to output value”0″ to port pins of PORT “C”. now if u send PORTC=ff; this will make all pins high on PORTC. similary you can send any value to the PINs pf any port.
get back to the program again.
void main() {
TRISC = 0; PORTC = 0; //set port “c” as output and send a value0 i,e pins at 0v
while(1) {
PORTC = ~PORTC; /in the loop negate value at PORTC i,e 5v (logic 1)
Delay_ms(1000); //Give a delay!!
} }
There you go . you have your first program ready.Now i aquezed a program here just to give you the whole concept for you to get a proper view of the whole thing.
Well Here below I have given it clearly
issue 1: SETTING OF PORT : This is the first thing you must do in your program. set what type of I/O the different ports will do.
OUTPUT INPUT TRISA=0; TRISA=1;
TRISB=0; TRISB=1;
TRISC=0; TRISC=1;
Rhe above commands will make the whole 8 bit PORT as input or output
issue 2: SETTING INDIVIDUAL BITS FOR I/O: In projects where you want to want to monitor indivival pins as input and the other pin of the same port as output tou will need this type of initializations. And you can do it this way as below.
TRISA = 0b11101001 TRISB = 0b11111110
now here above PORTA’S second,third and fifth pins are set “0″ ie to outputs and other pins as inputs.In the second comman PORTB’S first pin only is set to output and the other pins are all set to output.(NOTE WHILE USING PORTA write this in main–> ADCON1=0×06 i’l explainwhy later).
Thats it?!!!
are you still writing this?
shreedar.. i’l write more after this… i’l mork on the blog after aug 30. busy till then. but will work out all details here as days go by.
I thought you were busy till Aug.2006 ,this is Jan 2007….
Your article is brilliant, please continue.
Your tutorial is great !!
Can plz take a little more pain to tell about the programmer to use or if there is any other way i can make my own programmer to program 16F877.
Hi , about the programmer , you can make one for yourself. I youwant to buy have a look at http://invobot.com or mail me .
u have given a valuable info.. can u say about PIC16F877/874 microcontroller….. wil it be useful in converting the EEG signals….?
i need a coding for apr 6016