Documente Academic
Documente Profesional
Documente Cultură
1
• PIC16C7X have 3 timer modules
1 2 3
2
• Pre-scaler and Post-Scaler:
We are using timer 0 at 4Mhz
One increment of Timer 0 in 8 bit mode will take
4 Clock Cycles = 1 µ Sec
Pre-scaler in (1:1)
If Pre-scaler changed to (1:2)
4 Clock Cycles = 2 µ Sec
If Pre-scaler changed to (1:8)
4 Clock Cycles = 8 µ Sec
If Post-scaler (2:1)
PIC takes 2 Overflow of counter to set Interrupt bit.
If Post-scaler (4:1)
PIC takes 4 Overflow of counter to set Interrupt bit.
If Post-scaler (8:1)
PIC takes 8 Overflow of counter to set Interrupt bit.
5
6
Option Register: R/W Register
7
-ve
+ve
8
Additional Point to be remembers for timer
• Prescaler is assigned - (timer/counter),
TMR0 register = Written, then prescaler = 0
• Prescaler assigned - WDT,
CLRWDT, clear “prescaler and WDT”
• TMR0 register - timer, start two instruction cycles
delay.
• Sleep mode, oscillator = off. Overflow cannot
occur no pulses to count. TMR0 overflow
interrupt cannot wake up the processor from
Sleep mode.
• GIE and TMR0IE bits of the INTCON register
should be set.
9
Timer 1 Timer 1 (TMR1)
16-bit timer/counter
11
12
T1SYNC = 1
External
clock input is not
Timer 1
synchronized.
Operation
Asynchronized
Timer Mode Counter Mode
Synchronized
T1SYNC = 0 Counter Mode
External clock input is
synchronized with What happens now in Sleep mode ?
internal phase clocks.
13
Oscillator does not depend on internal clocking
TMR1 Prescaler:
Operate even in sleep mode Prescaler - 1, 2, 4 or 8 divisions
Enabled T1OSCEN, T1CON register of the clock input.
Programmer must provide a software time delay - not directly R/W.
Prescaler
to ensure proper oscillator start-up
TMR1 Oscillator:
RC0/T1OSO & RC1/T1OSI - get pulses
peripheral electronics.
RC0 &TMR1
RC1 -Gate:
simultaneously configured for
Sourcequartz
Low Power is software configurable
oscillator.
gate allows the timer to directly
time external events
14
Timer 2 Timer 2 (TMR2)
8-bit timer with Prescaler and Postscaler
15
16
Interrupts
Polling
External
System
Interrupts
Software Hardware
Interrupt Interrupt
Request from software Request from external
17
Hardware device
Hardware Interrupts
IE = 1
0
Maskable
Non Interrupts
Maskable Interrupts
19
20
5 registers that used to control the operation of
Interrupts
• INTCON
• PIE
• PIR
21
Interrupt Registers
INTCON Register
22
INTCON Register
23
INTCON Register
25
RETFIE
GIE = 0 GIE = 1
26
Interrupt Registers
27
Interrupt Registers
28
Interrupt Registers
29
30
org 0x00
goto start
movlw 0x07
movwf DAT2H
movlw 0xa0
movwf DAT2L
movf DAT1H, W
addwf DAT2H, W
addwf RESH, W
movwf RESH
return
end
32
; Interrupt
; RB0 - external interrupt
#INCLUDE "p16f877.inc“
org 0x00
goto main
org 0x04
goto isr
org 0x100
main: bsf STATUS, RP0
bcf STATUS, RP1
movlw 0x7f ; pull up
movwf OPTION_REG
movlw 0x00
movwf TRISC
movlw 0x01
movwf TRISB
movlw 0x90
movwf INTCON
bcf STATUS, RP0
movlw 0xff
movwf PORTC
33
xx: goto xx
isr: movlw 0x00
movwf PORTC
bcf INTCON, INTF
call delay
movlw 0xff
movwf PORTC
bsf INTCON, GIE
RETFIE
delay: movlw .500
movwf 0x21
d1: movlw 0xff
movwf 0x22
d2: nop
decfsz 0x22,1
goto d2
decfsz 0x21,1
goto d1
return
end
34
movlw 0x00
movwf PORTC
bcf INTCON, INTF
call delay
movlw 0xff
movwf PORTC
bsf INTCON, GIE
RETFIE
delay: movlw .500
movwf 0x21
d1: movlw 0xff
movwf 0x22
d2: nop
decfsz 0x22,1
goto d2
decfsz 0x21,1
goto d1
return
end 35
Front Panel I/O Soft keys
36
37
Front Panel I/O Soft keys
• LCD Alphanumeric Display
• Key Switches
• Rotary Pulse Generator (RPG)
38
• ROTARY PULSE GENERATORS (RPG’S) TRANSFORM SHAFT
ROTATION
39
40
State Machines and Key Switches
Action
41
42
Display Plus RPG USE
43
44
45
Display of Variable String
46
47