Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Micro
1. 09-EE-88 Page 1
MICROCONTROLLER
( PIC 18F458)
Microcontroller
A microcontroller is a small computer on a single integrated
circuit containing a processor core, memory, and programmable input/output
Peripherals.
In lab we are working on 18F458,it has 5 ports,
PORTS: group of pins
PORT A : having 7 pins
PORT B,PORT C,PORT D :8 PINS
PORT E: having 3 pins
PORTX : To store data ,port register is used
TRISX:Tri-state
0 is used for output
1 is used for input
2. 09-EE-88 Page 2
Simple Binary Counter
Code:
void main()
{unsigned char c=0 ;
trisB=0x00; //make port B as output
PORTB=c;
while(1) //Infinite loop like for (;;)
{PORTB=c ;
c++ ;
delay_ms(500);}} //time delay in miliseconds}}
Proteus simulation
3. 09-EE-88 Page 3
TIMERS
There are Four timers in 18F458.
8 bit Timer : a timer in which maximum value that can be implemented is 256
16 bit Timer: a timer in which maximum value that can be implemented is 65536
The clock source can be internal or external.if we use internal clock source ,then 1/4th
Of the freq of the crystal oscillator on the OSC1 And OSC2 pins .therefore it is used
For time delay generation ,so they are called timersBy choosing external clock option ,we feed
pulse through any pin of uC. This is called Counter.
First we will discuss about timers
4. 09-EE-88 Page 4
EXAMPLE:
void tmo_delay();
void main()
{trisB=0x00; //make portB as output
portB=0x00; // all pins of port B are given value =0
while(1) //infinite loop
{
portB=0xff; // all pins of port B are given value =1
tmo_delay(); //function call
portB=0x00; // all pins of port B are given value =0
tmo_delay(); // function call
}}
void tmo_delay()
{
T0CON=0X08;
TMR0H=0X00;
TMR0L=0X00;
T0CON.TMR0ON=1 ;
T0CON.TMR0IF=0 ;
while(intcon.tmr0if==0) ;
t0con.tmr0on=0 ;
intcon.tmr0if=0 ;
}
6. 09-EE-88 Page 6
Timers as Counters
Timers can also be used as counters to count events happening outside
pic18F458.in counter mode the registers such as T0CON , TMR0H,TMR0L are the
same as for the timers discussed.
EXAMPLE:
void cnt_0( ) ;
void main( )
{
trisa.f4=1;
trisb.f0=0;
trisd=0x00;
porta.f4=0;
portb.f0=0;
portd=0x00;
while(1)
{
cnt_0 ( );
} }
Unsigned char cnt=0;
Unsigned char c=0
void cnt_0( )
{tmr0l=0x00;
t0con=0x68;
intcon.tmr0if=0 ;