08.601 MBSD Module 2
08.601 MBSD Module 2
08.601 MBSD Module 2
Page 1
8051 Timer modes: 1. Mode 1 programming 16 bit timer/counter TLx hold lower byte of timer/count value (00H to FFH) THx hold upper byte of timer/count value (00H to FFH) Allows 0000H to FFFFH values TLx acts as 8-bit prescaler
Page 2
Steps to program: 1. Select timer by TMOD register 2. Load THx and TLx values 3. Run timer by setting TRx bit in TCON 4. Overflows occur TFx becomes high and monitoring it get the delay by timer or count value 5. Stop the timer by TRx = 0 6. Clear the flag TFx = 0 7. For continuous operation repeat the process from loading values to THx and TLx
Page 3
Page 4
REPEAT:
DELAY: WAIT:
Page 5
0000 to 1FFFH count values Count value N = 8192 (Td / Tt) Let N = 8182 = 1FF6H = 0001 1111 111 1 0110 b Then load TLx = 0001 0110b = 16H and THx = 1111 1111b = FFH All other operations are similar to mode 1
3. Mode 2 programming 8-bit auto reload mode, values ranges from 00H to FFH and THx hold it
Steps to program: Select timer by TMOD Load count value to THx and TLx Start timer by TRx = 1 When overflows in TLx results TFx set to 1 and THx value reloaded to TLx Stop timer by setting TRx = 0 and reset flag TFx = 0 For continuous operation, start timer again
Page 6
4. Mode 3 programming Split timer mode Timer 0 is split into two 8-bit timers TL0 to hold count value for timer 0 with over flow setting in TF0 TH0 to hold count value for timer 1 (Timer 1 stopped from other mode, but can be switched into mode 0, 1 or 2) with overflow setting in TF1
Page 7
Counter applications: To count objects, measure unknown frequency etc. P3.4 (T0) and P3.5 (T1) pins are used Program 3: System to measure unknown frequency and display it to LCD: Solution: Circuit diagram:
ORG 0 MAIN: MOV TMOD,#00010101B ; Timer 1 as mode 1 timer & timer 0 as ;counter in mode 1 SETB INPUT ACALL LCD_INIT ACALL DELAY CONTINUE: MOV A,#80H ; DDRAM address of LCD LCALL CMD_WRITE LCALL DELAY MOV TL0,#00 ;Lower byte initial count value MOV TH0,#00 ;Higher byte initial count value SETB TR0 ;Start counter ACALL DELAY_1S ;Wait 1 second MOV A,TL0 ;Load lower byte count value to A ACALL HEX_2_BCD ;Convert count value to BCD MOV A,R7 ;3rd digit of BCD to A ACALL BCD_2_ASCII ;Convert BCD to ASCII ACALL LCD_DISPLAY ;Display 3rd digit to LCD MOV A,R6 ; 2nd digit of BCD to A ACALL BCD_2_ASCII ;Convert BCD to ASCII ACALL LCD_DISPLAY ;Display 2nd digit to LCD MOV A,R5 ; 1st digit of BCD to A ACALL BCD_2_ASCII ;Convert BCD to ASCII ACALL LCD_DISPLAY ;Display 1st digit to LCD CLR TR0 ;Stop counter CLR TF0 ;Clear counter flag ACALL DELAY ;Wait a short time SJMP CONTINUE ;Repeat the process DELAY: MOV TH1,#0F8H ; 2ms delay program
Page 9
WAIT_2m:
DELAY_1S: MOV R0,#0FH NEXT: MOV TH1,#00 MOV TL1,#00 SETB TR1 WAIT_1S: JNB TF1,WAIT_1S CLR TR1 CLR TF1 DJNZ R0,NEXT RET ;LCD initializing LCD_INIT: CLR E MOV A,#38H LCALL CMD_WRITE LCALL DELAY MOV A,#01H LCALL CMD_WRITE LCALL DELAY MOV A,#0CH LCALL CMD_WRITE LCALL DELAY MOV A,#06H LCALL CMD_WRITE LCALL DELAY RET CMD_WRITE: MOV LCD_DATA,A CLR RW CLR RS SETB E
;Clear display
;E = 0 ;RW = 1 ;RS = 1
LCD_DISPLAY:
HEX_2_BCD:
;Hex number divided by 100 ;3rd digit of BCD to R7 ;Reminder to A ;Reminder divided by 10 ; 2nd digit of BCD to R6 ;Reminder is 1st digit of BCD and move to R5
BCD_2_ASCII:
Page 11
MAIN:
MOV TH0,#0C4H MOV TL0,TH0 LCALL LCD_INIT CONTINUE: SETB TR0 NEXT: MOV R3,TL0 MOV A,#88H ACALL CMD_WRITE ACALL DELAY MOV A,R3 ADD A,#3CH ACALL HEX_2_BCD MOV A,R6 ACALL BCD_2_ASCII ACALL LCD_DISPLAY ACALL DELAY MOV A,R5 ACALL BCD_2_ASCII ACALL LCD_DISPLAY ACALL DELAY JNB TF0,NEXT CLR TR0 CLR TF0 SJMP CONTINUE All subroutines are similar to previous example.
Department of ECE, VKCET
; Timer 0 as counter in mode 2 & timer 1 as ;timer in mode 1 ; Initial count to timer 0, 256 60 = 196 = C4H
;If count 60 go to label NEXT ; Stop counter ; Clear counter flag ; Continue the process
Page 12
Set TRx = 1 and timer starts or stop according to the pulse by the switch connected to INTx pins
Page 13
Page 14
Page 15
EA Global interrupt enable bit, set to 1 to enable all interrupts ET2 Enable Timer 2 interrupt (only in 8052) ES Enable Serial port interrupt, set to 1 to enable serial port interrupt ET1 Timer 1 overflow interrupt EX1 Enable External interrupt 1 (INT1 ) ET0 Enable Timer 0 overflow interrupt EX0 Enable External interrupt 0 (INT0) 2. IP (Interrupt Priority) Register 8-bit, bit addressable SFR byte address: B8H
PT2 Priority Timer 2 (only in 8052) PS Priority of Serial port interrupt , set to 1 for highest priority , else default priority PT1 Priority of timer 1 interrupt, set to 1 for highest priority , else default priority PX1 Priority of external interrupt 1 (INT1), set to 1 for highest priority , else default priority PT0 Priority of timer 0 interrupt, set to 1 for highest priority , else default priority PX0 Priority of external interrupt 0 (INT0), set to 1 for highest priority , else default priority
Department of ECE, VKCET Page 16
Page 17
ISR_T1:
MAIN:
; TIMER 1, MODE 2, AUTO RELOAD ; COUNT VALUE FOR 0.1666mS ; EA =1 and ET1 = 1
WAIT:
Program 2: Program to generate a square pulse of 9 kHz at pin P0.0 and toggle pin P2.0 for every 1 second. ORG 0 LJMP MAIN ORG 000BH CPL P0.0 RETI ORG 001BH LJMP WAIT_1S ORG 0030H MOV TMOD,#00010010B MOV TH0,#0CCH MOV TL0,TH0 MOV TH1,#4CH MOV TL1,#00H MOV R0,#00H
ISR_T0:
ISR_T1:
MAIN:
; TIMER 1 & 2, MODE 2 ; COUNT VALUE FOR 55us ; COUNT VALUE FOR 50ms
Page 18
WAIT: WAIT_1S:
RETURN:
Programming External Hardware Interrupts INT0 (P3.2) and INT1 (P3.3) Activating these interrupts, 8051 execution jumps to the ISRs of IVT location 0003H and 0013H respectively Enabled by IE register Two type triggering: Level triggered
Edge triggered
Page 19
Lower nibble IEx : set to 1 by microcontroller when external interrupt edge (H to L) is detected, cleared by microcontroller when the interrupt is processed ITx : Interrupt type control bit, set to 1 specify falling edge triggering external interrupt, cleared to 0 specify low level triggered external interrupt
Minimum duration for low level triggering signal is 4 Machine cycles Minimum pulse duration to detect edge triggered interrupt is 1 Machine cycle HIGH and 1 Machine cycle LOW
Difference between RET and RETI instructions Both return to main program RETI clears ISR flags, indicates the service is over If RET is used all other lower priority interrupts are blocked
Page 20
Program: ORG 0 LJMP MAIN ORG 0003H LJMP UP ORG 0013H LJMP DOWN MAIN: MOV R1,#00 MOV DPTR,#SEG_CODE CONTINUE: CLR A ADD A,R1
Department of ECE, VKCET Page 21
DOWN: DECR:
SEG_CODE: DB 11000000B DB 11111001B DB 10100100B DB 10110000B DB 10011001B DB 10010010B DB 10000010B DB 11111000B DB 10000000B DB 10011000B END
Page 22
Serial communication uses single or pair of data line instead of 8-bit data line of parallel communication For long distance transmission serial data is converted/de-converted into tones by modem
Page 23
2. Duplex
Page 24
8051 has full-duplex, asynchronous serial port, ie two lines and one byte transmission at a time Asynchronous serial communication data framing: Character oriented data transmission Each character is placed between a start and stop bits and is called framing
Mark is 1 signal to indicate no transfer Space is 0 signal indicates transfer is over Framing for ASCII of character A ASCII for A is 41H
Transmissions begins from start bit 0 followed by D0 (LSB) and ends at stop bit 1 after D7 (MSB) for 8-bit UART For 7-bit mode (older system), transmission end at D6 and 2 stop bits are used Other system have Parity bit with 7 or 8 bit character bits and start/stop bits are also included for data integrity
Page 25
Page 26
Pin 1 GND Pin 2 TxD (transmitted data) Pin 3 RxD (Received data) Other pins for USART connections DB9 Connector (9 pin) DB9P (Male) and DB9S (Female)
Pin 2 RxD (Received data) Pin 3 TxD (Transmitted data) Pin 5 GND Other pins for USART
Page 27
8051 serial port programming SFRs for serial port programming: SBUF: To hold the byte of data for Txr or Rxr SCON: For select serial port mode, serial interrupt flags, receiver enable etc TH1, TMOD and TCON: To set baud rate using timer 1. TH1: Hold baud rate information, TMOD: To select timer 1 in auto-reload mode(Mode 2), TCON: To run the timer 1 IE and IP: If program is in ISR of serial port PCON: To double the selected baud rate SBUF: Serial buffer 8-bit register to hold serial data for txn or rxn Physically two register with one address 99H, one register only have write operation (for Txn) and other for read operation (for Rxn)
Page 28
SM0 & SM1: Serial port Mode bits SM2: Multiprocessing communication enable bit, 1 to enable & 0 to disable REN: Receiver Enable bit, 1 to enable & 0 to disable TB8: Transmitted bit 8 (9th bit), 1 or 0 by program RB8: Received bit 8 (9th bit) TI: Transmit Interrupt Flag bit, 1 if transmission is over & cleared by sw RI: Receive Interrupt Flag bit, 1 if receiving is over & cleared by sw
Mode 0: Shift register mode SBUF configures to receive/transmit 8 data bits using RxD pin (P3.0) for both functions. TxD serves as clock, where it serve a clock frequency of f/12 to external circuits Timing diagram:
Page 29
Mode 1: 8-bit UART, variable baud rate mode SBUF configures to receive 8-bit data, one start bit and a stop bit for fullduplex UART The format (framing) of data is:
After transmission (stop bit) TI flag (SCON.1) set to 1 Receiving bits at the center of bit time (inverse of baud rate), to avoid false triggering (cause noise) For receiving, RxD pin bits are shifted into SBUF at programmed baud rate only if: RI = 0 and SM2 = 0 After discarding start bit, 8 data bit go to SBUF, stop bit saved to RB8 (SCON.2) and RI = 1, indicates receiving data is over Mode 1 Baud rate: Timer 1 in its auto-reload mode (mode 2) is used to generate baud rate Timer 1 overflow flag TF1 determine baud frequency Baud frequency generated by timer 1:
else
f is Xtal frequency and TH1 is 8-bit value to program different baud rate
Department of ECE, VKCET Page 30
Q: With Xtal frequency 11.0592MHz, find the TH1 value for getting baud frequencies a) 1200 bps b) 9600 bps Solution: For 2400 bps:
Mode 2: 9-bit UART, fixed baud rate mode Similar to mode 1, but 11 bits are transmitted: (1 start bit, 9 data bit and 1 stop bit). 9 th data bit is from TB8 bit of SCON register Baud rate can be programmed as:
Data format:
Page 31
Note: Commonly used mode is mode 1: 8-bit UART variable baud rate, because of its simplicity and versatility with other data communication devices Program 1: Send a string of message to 8051 TxD pin (P3.1) ORG 0 LJMP MAIN ORG 30H MOV TMOD,#00100000B MOV TH1,#0FDH MOV TL1,TH1 SETB TR1 MOV SCON,#01000000B MOV DPTR,#MESSAGE CLR A MOVC A,@A+DPTR CJNE A,#00,SEND SJMP STOP MOV SBUF,A JNB TI,WAIT CLR TI INC DPTR SJMP NEXT
MAIN:
; Timer 1, mode2 ; Baud rate 9600bps ; Start timer ;Serial mode 1 ;Pointer for message string ; Access code memory for message ;If null character, stop txn.
NEXT:
; SBUF = A, data to Txr ; Wait for Txn Flag = 1 ; Clear Txn Flag for next txn ;For next character
Page 32
MAIN:
CONTINUE: NEXT_RXR:
NEXT_TXR:
SEND_CHAR:
RECEIVE:
SEND: WAIT:
Page 34
Page 35
Step size (mV) 5/256 = 19.53 4/255 = 15.62 3/256 = 11.71 2.56/256 = 10
Page 36
Page 37
(Xtal and RST connections are not shown) Algorithm: 1. Start 2. Set Port 1 as input 3. Set EOC (INTR) pin as 1 4. Set SOC (WR) pin as 1 5. Set OE (RD) pin as 1 6. Clear SOC (WR) pin to 0 7. Wait 150ns 8. Set SOC (WR) pin as 1 9. If EOC (INTR) pin is high, wait in this step, else go to next step 10. Clear OE (RD) signal 11. Read digital data from Port 1 12. Write digital data to Port 0 13. Go to step 6 for repeat the process (Assume crystal frequency to 8051 is 12 MHz)
Department of ECE, VKCET Page 38
ORG 0 LJMP MAIN ORG 30H MAIN: MOV P1, #FFH SETB EOC SETB SOC SETB OE CONTINUE: CLR SOC NOP NOP SETB SOC WAIT: JB EOC, WAIT CLR OE MOV A, IN_DATA MOV OUT_DATA, A SJMP CONTINUE
Page 39
Functions of pins: Pins Functions Vcc & GND Power supply pins VEE -ve power supply (-12V) IoAnalog current output A1(MSB) to Digital input data lines A8(LSB) Vref(+) and Reference voltage to provide reference current Iref Vref(-) Compensation Compensation capacitor for ve power supply
Page 40
Where R14 is the resistance connected to pin 14 DAC0808 interfacing circuit: The output of DAC0808 is current and have ripples Output require I-V converter followed by LPF Circuit diagram:
Vout = Io Rf For LPF RC value can be determined by either the maximum frequency of the required analog output or by the data transfer rate of 8051
Page 41
Using different delay programs rectangular wave can be generated. Saw tooth and triangular wave generation: By sending data from 00H to FFH continuously with one step size. The frequency and peak amplitude of the signal are maximum value if there is no delay introduced between each step Frequency can be changed by including required delay between each step. Peak voltage of the wave is reduced by changing the maximum data. To generate triangular wave send data from 00H to FFH for rising and FFH to 00H for falling with one step size. Similar to other waves, the frequency and amplitude can change.
Page 42
DECREMENT:
Applications: Temperature measurement system: The basic block diagram of temperature measurement system is:
Sensor are thermostats, thermisters or any other temperature sensors Usually LM34/35 IC temperature sensors are used; whose output voltage is directly proportional to the temperature as given below: For LM35 temperature range -55 to 150oC, 10mV/oC sensitivity Signal conditioner is either amplifier, I-V or V-I converter etc. to provide suitable input signal to ADC ADC converts analog signal corresponding to temperature into digital data Microcontroller controls ADC and acquire digital data corresponding to temperature and process it to get a suitable signal to display
Page 43
Signal conditioning is not used Program to read data corresponding to temp and display its BCD data. (Assume that calibrated output is available at ADC output: ie for 0 oC data is 0000 0000, for 10 oC data is 0000 1010, for 50oC data is 0011 0010, and so on..) OE SOC EOC BIT BIT BIT P2.0 P2.1 P2.2
MAIN: CONTINUE:
ORG 0 MOV P1, #FFH SETB EOC ACALL ADC_START ACALL ADC_READ MOV R0, A ACALL HEX_BCD MOV P3, A CONTINUE
ADC_READ:
HEX_BCD:
Page 45
Different views:
Page 46
Four stator motor also called four-phase or uni-polar stepper motor Total 6 leads: 4 leads for stator windings and 2 for center tapped common windings
As the sequence of pulse is applied to each stator winding, the rotor will switch to next step due to the flux linkage across the stator and rotor Rotor of conventional motors runs freely, but stepper motors rotor moves in a fixed repeatable increment, allows a precise position The most common stepper motors have four stator windings that are paired with a center-tapped common. This type of stepper motor is commonly referred to as a four-phase stepper motor The center tap allows a change of current direction in each of two coils when a winding is grounded, thereby resulting in a polarity change of the stator.
Page 47
Page 48
Consider a motor; Stator with 8 teeth and rotor with 6 teeth, have 15o step angle Step angle is minimum degree of rotation associated with a single step Different motor have different step angle Standard angles and steps per revolution (or 360 degree) are: 0.72 500 1.8 200 2.0 180 5.0 72 7.5 48 15 24 Steps per second and rpm relationship is:
After completing every four steps, the rotor moves only one tooth pitch The smaller the step-angle, the more teeth the motor passes Eg. In a stepper motor with 200 steps per revolution, its rotor has 50 teeth since 4 x 50 = 200 steps are needed To allow for finer resolutions, all stepper motors allow what is called an 8-step switching sequence. Its also called half-stepping, since each step is half of the normal step angle
Department of ECE, VKCET Page 49
Full step 4-step wave drive sequence (clock wise) Step 1 2 3 4 Winding Winding Winding Winding A B C D 1 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0
Page 50
Step 1 2 3 4 5 6 7 8
Motor speed Measure in steps per second; function of switching rate Determined by delay introduced between each step Eg. Let step angle of motor is 7.5 degree. If required RPM is 20, then steps per second = 20 x 48 /60 = 16 Therefore for one step 1/16 = 62.5ms is required Then pulse duration of a step sequence signal is 62.5ms
Department of ECE, VKCET Page 51
Page 52
DELAY:
WAIT:
FS_WAVE:
Program: MAIN: CONTINUE: ORG 0 SETB P1.0 MOV TMOD,#01 MOV C,P1.0 JC C_WISE MOV DPTR,#ACW SJMP STRT MOV DPTR,#CW MOV R0,#08H CLR A MOVC A,@A+DPTR MOV P2,A ACALL DELAY_1S JNC DECR INC DPTR DJNZ R0,REPEAT SJMP CONTINUE DEC DPL SJMP NEXT ;P1.0 as input ;Timer 0 for delay ;Status of P1.0 to CY ;If P1.0 is 1, go to label C_WISE for CW ;rotation ;Pointer for ACW step sequence ;Pointer for CW step sequence ;Counter for half-step sequence
NEXT: DECR:
Page 54
DELAY:
WAIT:
Program to rotate stepper motor with 1.8o step angle, at a speed of 6 RPM in 360o clockwise for 2 times and 11 RPM in 360 o anti-clock wise direction for 4 times continuously (Xtal frequency of 8051 is 11.0592MHz ) Solution: Step sequence for normal drive as per the connection shown in the circuit is: For clockwise rotation: Step Winding A Winding B Winding C Winding D (P2.0) (P2.3) (P2.2) (P2.1) 1 1 0 0 1 1 2 0 0 1 0 3 0 1 1 0 4 1 1 0 o For RPM = 6, Step angle = 1.8 Steps/sec = 6 x 200/60 = 20 For one step 1/20 = 50ms Design 50ms delay program After full step pulses 1.8 x 4 = 7.2 degree rotation takes place, then for 360 degree, repeat the process for 360/7.2 = 50 times Continue the above process for two times
Page 55
1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 For RPM = 11, Step angle = 1.8o Steps/sec = 11 x 200/60 = 36.66 For one step 1/36.66 = 27.27ms (use 25ms) Design 25ms delay program After half step pulses 1.8 x 8 = 14.4 degree rotation takes place and for 360 degree repeat the process for 360/14.4 = 25 times Continue the above process for 4 times ORG 0 MOV TMOD,#01 MOV R2,#02H ;counter for 2 times cw rotation MOV R1,#32H ;counter for 50 times to rotate 360o MOV R0,#04H MOV DPTR,#FS_CW CLR A MOVC A,@A+DPTR MOV P2,A ACALL DELAY ;25ms delay ACALL DELAY ;25ms delay INC DPTR DJNZ R0,NEXT DJNZ R1,REPEAT DJNZ R2,CONTINUE MOV R2,#04 ;Count for 4 times acw rotation MOV R1,#19H ;count for 25 times to rotate 360o
Page 56
CONTINUE1:
;25ms
DELAY:
WAIT:
Page 57
Timing diagram:
Page 58
Note: DDRAM Display Data RAM Where I/D = 1, increment DDRAM address, cursor moves to right I/D = 0, decrement DDRAM address, cursor moves to left SH = 1, shift entire display according to I/D
Department of ECE, VKCET Page 59
AC Address Counter
DL = 1, 8-bit bus mode DL = 0, 4 bit bus mode N = 1, 2 line display mode N = 0, 1 line display mode F = 1, 5 x 10 dots font F = 0, 5 x 7 dots font Address for DDRAM: AC6 to AC0 are:
The for position 1 in line 1 the command byte is 1000 0000 = 80H, for position 2 : 1000 0001 = 81H .
Department of ECE, VKCET Page 60
Xtal, RST and Power supply connection are not shown Program: Algorithm: Main program Steps: 1. Start 2. Write command byte to LCD for function setting. Command byte: 0011 1000 = 38H 3. Wait minimum 40s 4. Write command byte to LCD for function setting. Command byte: 0000 0001 = 01H 5. Wait minimum 1.64ms 6. Write command byte to LCD for display on and cursor blinking. Command byte: 0000 1111 = 0FH 7. Wait minimum 40s
Department of ECE, VKCET Page 61
Page 62
MAIN:
NEXT:
LINE_1:
CMD_WRITE:
DATA_WRITE:
DELAY_40u:
Page 65
WAIT_2m:
MESSAGE:
Keyboard Interfacing Keyboard is widely used input device along with output devices like LCD, seven segment displays etc To interface keyboard, understanding keyboard mechanism, key pressing and detecting is essential Interfacing keyboard to 8051 Interfacing program must guard against two factors: a. Human factors: 1. More than one key pressed 2. Key pressed and held 3. Rapid key press and release b. Key factors Bouncing of key contacts Key configurations Commercially available key configurations are: 1. Lead per keyboard
4 input and 4 output lines are required to read the keys 3. Coded key board
Page 67
Scanning and identifying steps Ground all rows , P1.3 P1.0 =0000 Read all columns, if data read P2.3 P2.0 = 1111, no key is pressed Continue above process until a key is pressed If P2.3 P2.0 = 1101, one of the key in column 1 is pressed To identify the key in the column, ground row 0 only, P1.3 P1.0 = 1110 Read columns, if P2.3 P2.0 = 1111 , no key in the row 0 is pressed Continue the above process until pressed is detected If key 5 is pressed, then read data during scanning is P2.3 P2.0 = 1101 Identifying step; grounding P1.3 P1.0 = 1101, read data becomes P2.3 P2.0 = 1101
Page 68
K2:
OVER:
OVER1:
WAIT:
Page 70
. 4. PIC18 High End Core Devices (ex:PIC18Cxxx) New high end PIC architecture It inherits most of the features and instructions of the 17 series, 77 instructions, much deeper call stack (31 levels deep) The call stack may be read and written Offset addressing mode A new indexed addressing mode in some devices 5. PIC24 and dsPIC 16 bit Microcontrollers Architectures differ significantly from prior models. dsPICs are Microchip's newest family (started in 2004) Digital signal processing capabilities. Microchip's first inherent 16-bit (data) microcontrollers. Hardware MAC (multiply-accumulate) Barrel shifting Bit reversal (16x16)-bit multiplication Other digital signal processing operations. Can be efficiently programmed in C . .PIC16F87X Microcontrollers Mid range core 28/40-Pin 8-Bit CMOS FLASH Microcontrollers PIC16F873, PIC16F874 (28 pin ICs) PIC16F876 and PIC16F877 devices (40 pin ICs) Microcontroller Core Features: High performance RISC CPU Only 35 single word instructions All single cycle instructions except for program branches which are two cycle Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data Memory (RAM) Up to 256 x 8 bytes of EEPROM Data Memory Pin out compatible to the PIC16C73B/74B/76/77
Department of ECE, VKCET Page 72
Page 73
Page 74
. Pin details:
Page 75
Page 76
Page 77
Page 78
8 bit Contains the arithmetic status of ALU To select register bank File Selection Register (FSR) Data pointer, used for indirect addressing in the whole register file IO ports Memory organization Three memory blocks: 1. Program memory (Flash) 2. Data memory (RAM) (Separate bus for both memory) 3. Data EEPROM Program memory mapping 8k x 14 word ROM (Flash or EEPROM)
Page 79
Program Counter (PC) .Keeps track of the program execution by holding the address of the current instruction .PCL and PCLATH SFRs for accessing 13 bit PC
PCL (8 bit) is readable and writable PCH (5 bit) not readable, but indirectly writable by PCLATH least 5 bits Stack memory The stack space is not part of either program or data space and the stack pointer (SP) is not readable or writable. Stack is a special block of RAM memory The PC is PUSHed onto the stack when a CALL instruction is executed, or an interrupt causes a branch.
Department of ECE, VKCET Page 80
Page 81
Page 82
By RP0 and RP1 bits in STATUS register any one bank can be selected Using IRP bit in STATUS register direct or indirect
Page 83
Data EEPROM (256 bytes) Similar to Program flash, but r/w operation is byte , where in program memory it is word r/w operation Write operation can be performed during normal power source Vdd SFRs for accessing Data EEPROM EEADR :Hold data EEPROM address EEDATA : Hold the data from/to the data EEPROM EEDATA : EEDATH Hold 14 bit data from flash memory EEADRH:EEADR hold 13 bit flash memory address EECON1 & EECON2 : Control registers for configure IO Ports 1. Port A and TRISA Registers PORTA is a 6-bit wide, bi-directional port 5 analog inputs and timer 0 clock input are multiplexed with this pins The corresponding data direction register is TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output 2. Port B and TRISB registers PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input Clearing a TRISB bit (= 0) will make the corresponding PORTB pin an output
Department of ECE, VKCET Page 84
4. Port D and TRISD PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as an input o output. PORTD can be configured as an 8-bit wide microprocessor port (parallel slave port) by setting to PSPMODE. In this mode, the input buffers are TTL. 5. PORTE and TRISE Register PORTE has three pins which are individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers. The PORTE pins become the I/O control inputs for the microprocessor port Three analog inputs are multiplexed with this pins TIMER0 MODULE The Timer0 module timer/counter has the following features: 8-bit timer/counter Readable and writable
Department of ECE, VKCET Page 85
Page 86