SlideShare a Scribd company logo
Contents Page
1B-i: Heart Monitor 1
1B-ii: Smart Socket 5
Appendix-i: Subroutines 9
Appendix-ii: Assembly
Code (1B-i)
10
Appendix-iii: Assembly
Code (1B-ii)
14
H63ECH - Embedded Computing
(AUT 15 -16)
Coursework 1B
PIC16F887 Assembly Programming
Submitted By:
Osama Azim (ID: 023799),
M.Sc. Electronics Communication and Computer
Engineering
Coursework - 1B : PIC16F887 Assembly Programming
1 | H63ECH - Embedded Computing Osama Azim
1B-i : Heart Monitor
o Introduction:
With available on-board I/O's on the PIC Kit2 - one push button, eight LEDs - the
coursework objectives resemble a simplified heart beat monitor.
Following prominent features of a portable heart beat recorder/monitor were required to be
developed on a PIC16F887 Microcontroller (MCU) in PIC Assembly language using the
MPLAB assembler:
 User identification stored in device memory and displayed - emulated by storing
Student ID in MCU EEPROM and successful write operation indicated on LEDs
 Device ready or in standby mode - emulated by signaling an LED on/off
 Data-logging of heart beat sensor readings - emulated by blinking an LED
intermittently
 End of data-log - emulated by indicating appropriate LED sequence upon input from
a pushbutton
o State Diagram and Flow Charts:
Above described coursework objectives can be represented by following state diagram:
State actions:
State Ready: LED 0 is turned ON, initially device enters State Ready by a pushbutton press after EEPROM
data writing.
State Datalog: LED 0 maintained ON while LED 1 blinks intermittently, next transition is upon a
double click of pushbutton and further delay of 3 seconds. LED 4 turned on to indicate a
double press and hold on time.
State End: LED 0, LED 1 are turned OFF, LED 2 turned ON. Transition back to State Ready
on Button press.
Figure1: State diagram
State
Ready
State
DataLog
ButtonPress
= 0
ButtonPress = 1
Double Press = 1,
Delay 3 sec.
Button Double
Press = 0
State
End
ButtonPress = 1
ButtonPress
= 0
Main Program Flow Chart
No
No
No
Write Student ID to EEPROM
Start
Debounce
Button
Press?
Turn On LED 5,6,7 :
from Port D
Debounce
State Ready:
LED 0 ON,
LED 2 OFF
Button
Press?
State Datalog:
LED 1 OFF
Delay
Decrement ENDATAL
ENDDATAL
= 1?
State End:
LED-2 ON,
LED-0 OFF,
LED-1 OFF,
LED-4 OFF
LED 1 ON
Button
Press?
Delay
Yes
Yes
Double Click
Double
Click?
Load "10"
To ENDDATAL
Yes
Yes
No
No
Yes
Coursework - 1B : PIC16F887 Assembly Programming
3 | H63ECH - Embedded Computing Osama Azim
Flow Chart for Double Click:
Notes on double click:
 Hold time for continuous button press during LED 1 blink cycle can be adjusted by
loading appropriate value to DINTERVAL (for max press time) register.
 Second click wait time can also be adjusted similarly by loading an appropriate value
to DINTERVAL after first click release
Yes
From
Main
Program
Flow
Yes
Load DINTERVAL
(For maximum second click
wait time)
No
DINTERVAL
= 0 ?
No
Load DINTERVAL
(For maximum press time)
Timer
Button
Press?
Decrement
DINTERVAL
State Datalog:
Blink Routine
Button
Press?
Yes
No
Timer
Button
Press?
Load ENDDATAL,
LED-4 ON
Yes
Decrement
DINTERVAL
DINTERVAL
= 0 ?
No
Yes
No
Coursework - 1B : PIC16F887 Assembly Programming
4 | H63ECH - Embedded Computing Osama Azim
o Discussion and Conclusion:
All coursework objectives were realized with certain modifications and known issues, these
are noted in following points:
 A debounce subroutine was developed to filter out unwanted, noise like, pushbutton
transitions during button press. This subroutine, although effective, was not
extensively optimized and a more efficient debounce logic can be developed.
 The transition hold time of 3 seconds from State DataLog to State End is indicated by
LED 4 being turned ON, this also indicates a successful double press. Though not
essential, this feature was implemented for a better device state indication - as the
double click can often be disregarded due to exit from second click hold time or short
successive click interval.
 Upon detecting a click in between of State Datalog blink loop, LED 1 is maintained
ON until a second click is detected or maximum wait time for second click is reached,
whichever occurs earlier. The program developed could not check for double click
while blinking LED 1 simultaneously, but the LED 1 hold ON time during double click
subroutine can be reduced by adjusting the wait time for second click.
Conclusion and Learning outcome:
 Programming with a lower level language, assembly, is directly dependent on the
target CPU/MCU. This is in contrast with higher level languages like C - for which the
compiler provides an illusion of codes being generic for multiple machine
architectures.
 Considering that every CPU/MCU is designed with their respective assembly
instructions, programs written in assembly for a specific architecture is more robust
when compared to a higher level language.
 Due to its hardware dependent nature, optimum hardware utilization can be
achieved by programming in assembly. This is especially useful for embedded
applications, wherein a CPU/MCU is dedicated to execute predetermined tasks,
keeping cost of hardware down along with achieving a higher degree of reliability.
Coursework - 1B : PIC16F887 Assembly Programming
5 | H63ECH - Embedded Computing Osama Azim
1B-ii : Smart Power Socket
Introduction:
As described in the Coursework-1A report, the Smart Power Socket was conceptualized as an IoT device
with IP based remote switching and monitoring.
The features realized using the provided PIC16F887 MCU based PIC Kit 2 development board:
 A Button Press emulates the remote command to switch device On/Off. With an initial press of
pushbutton, appropriate LED is turned On or Off.
 Current consumed by appliance is emulated by varying the voltage supplied to MCU ADC
through the onboard potentiometer.
Usage of ADC :
The PIC16F887 ADC is configured with following parameters:
 Port: PORT A, PIN 0
 Channel: RA 0 - ADC channel 0
 ADC voltage reference: Positive: Vdd, Negative: Vss
 ADC conversion clock: Fosc/8
 Result Formatting: Left Justified
The conversion process is executed in following steps:
Figure 1: ADC conversion TAD Cycles
The output result format used is left justified, the ADRESH register that holds the conversion result has
following structure:
Coursework - 1B : PIC16F887 Assembly Programming
6 | H63ECH - Embedded Computing Osama Azim
Figure 2: ADRESH register format
The ADC conversion result is calculated using the formula:
ADC = VIN/VREF * 1023
The application designed for this coursework turns ON a respective LED in accordance to the voltage
level converted at the ADC. The PIC Kit 2 development board has 8 LEDs connected to PORT D.
Considering an input voltage range of 0V to 5V, each LED is stepped on a voltage of 0.625V (5V/8). The
reference ADRESH value to stitch LEDs is calculated below:
LED ON
Voltage In
(v)
ADC Value Binary
Decimal Ref
(ADRESH)
0 0.625 128 00100000 00 32
1 1.25 255 00111111 11 63
2 1.875 384 01100000 00 96
3 2.5 512 10000000 00 128
4 3.125 640 10100000 00 160
5 3.75 767 10111111 11 191
6 4.37 894 11011111 10 223
7 ~5 1019 11111110 11 254
o State Diagram and Flow Chart:
The program toggles between two states as explained below:
State OFF: All LEDs turned OFF, wait for push button to transition to State ON.
State ON: Capture ADC value and turn ON respective LED to signify voltage level. Next press
of Pushbutton makes the transition back to State OFF.
Figure1: State diagram
State
OFF
ButtonPress
= 0
State
ON
ButtonPress = 1
ButtonPress
= 0
ButtonPress = 1
Coursework - 1B : PIC16F887 Assembly Programming
7 | H63ECH - Embedded Computing Osama Azim
Flow Chart for Smart Plug:
Start
Move
ADRESH to W
Yes
Delay Cycle
for Capacitor
Start A2D
Conversion
A2D
Done?
Debounce
Button
Press?
Yes
No
No
Button
Press?
Yes
Clear PORT D -
All LEDs Off
No
YesADRESH =
"x" Volt Level?
No "x" matching
LED = ON
Clear
PORT D
Coursework - 1B : PIC16F887 Assembly Programming
8 | H63ECH - Embedded Computing Osama Azim
o Discussion and Conclusion:
Known Issues:
 After successive On/Off transitions, the LEDs were found not to turn on by press of
pushbutton, and would turn on only after a change in potentiometer value.
Design Limitations and Conclusion:
Achieving complex design objectives, such as IoT based control, through Assembly is a
lengthy process which would require extensive effort - these objectives can be achieved
with relative ease through higher level programming languages. The focus of this
coursework was not to implement a feature heavy design, but to understand the various
machine level operations such as calculated usage of ADC or utilization of MCU timers, for
example.
Assembly programming, as its uniquely defined for each device, enables complete hardware
usage of target CPU/MCU - this allows for an in depth understanding of the various
computing and peripheral components that make up a MCU. Although assembly codes are
not suitable for real world applications today, knowledge of the underlying hardware and
understanding of the "assembly program development approach" would encourage
programmers to develop efficient programs in higher level languages as well.
Coursework - 1B : PIC16F887 Assembly Programming
9 | H63ECH - Embedded Computing Osama Azim
Appendix - i : Subroutines
Subroutines used at multiple instances in Coursework:
COUNTD:
B7 B6 B5 B4 B3 B2 B1 B0
x x x x x x x 1/0
Appropriate COUNTD bit can be tested for required delay to achieve debounce
Flow Chart for
Timer Subroutine:
Using:
Overflow time = 4 * (1/Fosc) *
Prescale * (256-TMR 0)
We have:
Overflow Time = 6.55 x 10-2
sec
Flow Chart for
Delay subroutine:
Delay = (6.55 x 10-2
Sec) * (2X
)
Flow Chart for
Debounce Subroutine:
Yes
Timer
Timer
Rolled
Over?
No
Clear Interrupt
Flag
RETURN
No
Delay "x" ms
TIME1
=0?
RETURN
Yes
Move Time
Multiplier to
TIME1
Timer
Decrement
Time Multiplier
Moved to BUTTOND, and B0
tested for denounced Press
Move COUNTD
to BUTTOND
Yes
Debounce
Button
Press?
No
Delay
Increment
COUNTD
Button
Release?
No
Yes
Delay
Clear COUNTD
RETURN
Coursework - 1B : PIC16F887 Assembly Programming
10 | H63ECH - Embedded Computing Osama Azim
Appendix - ii : Coursework 1B-i , Heart Beat Monitor, Assembly Code
#include <p16F887.inc>
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF &
_CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
cblock 0x20
COUNTD
BUTTOND
TCOUNT
TIME
TIME1
COUNTER
DINTERVAL
ENDDATAL
endc
org 0
START: BSF STATUS, RP0 ;SELECT BANK 1
MOVLW B'00000111' ; CONFIGURE TIMER0 PRESCALER BITS
MOVWF OPTION_REG ; MOVE TO OPTION REG
MOVLW 0x01
MOVWF TRISB ; PORTB, PIN0 SET AS INPUT FOR SWITCH
CLRF TRISD ; PORTD SET TO ALL OUTPUTS FOR LEDs
BSF STATUS, RP1 ; SELECT REGISTER BANK 3
MOVLW 0X00
MOVWF ANSELH ; PORTB PINS SET AS DIGITAL INPUT
BCF STATUS, RP0 ; SELECT REGISTER BANK 0
BCF STATUS, RP1
CLRF PORTD ; INITIALIZE PORTD AS ALL OFF (LEDs)
CLRF COUNTD ; CLEAR GPR DATA
CLRF BUTTOND
CLRF COUNTER
CLRF TCOUNT
CLRF TIME
CLRF ENDDATAL
Coursework - 1B : PIC16F887 Assembly Programming
11 | H63ECH - Embedded Computing Osama Azim
BSF STATUS, RP1 ; SELECT BANK 2
MOVLW D'99' ; DECIMAL 99, LAST DIGITS OF STUDENT ID:023799
MOVWF EEDATA ; LOAD TO EEDATA
MOVLW 0x20 ; EEPROM ADDRESS
MOVWF EEADR
BSF STATUS, RP0 ; SELECT BANK 3
BSF EECON1, 2 ; WRITE ENABLE FOR EEPROM
BCF INTCON, 7 ; DISABLE GLOBAL INTERRUPTS
MOVLW 0x55 ; SAFETY PROCEDURE
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF EECON1, 1 ; START WRITING
BCF STATUS, RP0 ; SELECT BANK 0
BCF STATUS, RP1
BSF PORTD, 5 ; LED 5, 6, 7 ON TO INDICATE WRITE COMPLETE
BSF PORTD, 6
BSF PORTD, 7
S_READY: CALL DEBOUNCE1 ; CHECK DEBOUNCE, BUTTON PRESS
BTFSS BUTTOND, 0 ; BUTTON PRESS?
GOTO S_READY
BSF PORTD, 0 ; INDICATE STATE READY
BCF PORTD, 2 ; CLEAR INDICATION FOR STATE END
S_DATALOG: CALL DEBOUNCE1 ; CHECK DEBOUNCE, BUTTON PRESS
BTFSS BUTTOND, 0 ; BUTTON PRESS?
GOTO S_DATALOG
BLINK: BCF PORTD, 1 ; START BLINK, LED 1 = OFF
CALL DELAY260 ; LED 1 OFF DELAY
DECF ENDDATAL ; CHECK IF DATALOG STATE NEEDS TO END,
;DECREMENT ENDDATAL REGISTER
MOVF ENDDATAL, W ; CHECK IF ENDDATAL HAS REACHED 1
XORLW 1
BTFSC STATUS, Z ; IF YES, GOTO STATE END
GOTO S_END
BSF PORTD, 1 ; BLINK, LED 1 = ON
CALL DELAY260 ; LED 1 ON DELAY
BTFSC PORTB, 0 ; CHECK IF BUTTON IS PRESSED
GOTO BLINK ; IF NOT, LOOP BLINK
Coursework - 1B : PIC16F887 Assembly Programming
12 | H63ECH - Embedded Computing Osama Azim
GOTO DOUBLEC ; IF YES, CHECK FOR DOUBLE CLICK
S_END: CLRF ENDDATAL ; CLEAR ENDDATAL REGISTER
BSF PORTD, 2 ; INDIACATE STATE END BY LED 2 = ON
BCF PORTD, 0 ; TURN OFF OTHER LEDs
BCF PORTD, 1
BCF PORTD, 4
CALL DELAY1000
GOTO S_READY ; GO TO STATE READY, CHEC FOR NEXT
; BUTTON PRESS
DEBOUNCE1: BTFSC PORTB, 0 ; CHECK IF BUTTON PRESSED
GOTO DEBOUNCE1
CALL DELAY130 ; DELAY TO FILTER FALSE CLICKS
CLRW
INCF COUNTD ; INCREMENT DEBOUNCE COUNTS, TO
; B'00000001'
BTFSS PORTB, 0 ; CHECK IF BUTTON RELEASED
GOTO $-1
CALL DELAY130 ; DELAY TO FILTER FALSE RELEASE
MOVF COUNTD,W ; MOVE DEBOUNCE COUNT TO BITTOND. BUTTOND
; IS NOW B'00000001'
MOVWF BUTTOND
CLRF COUNTD ; CLEAR COUNTD REGISTER
RETURN ; RETURN FROM DEBOUNCE
DOUBLEC: MOVLW D'3' ; LOAD MAXIMUM PRESS DELAY TO DINTERVAL
MOVWF DINTERVAL
CALL DELAY520
BTFSC PORTB, 0 ; BUTTON STILL PRESSED?
GOTO CHECK ; IF NOT, CHECK FOR SECOND PRESS
DECR1: CALL TIMER ; DECREMENT MAXIMUM PRESS COUNT
DECFSZ DINTERVAL
GOTO DECR1
GOTO BLINK ; RETURN TO BLINK
CHECK: MOVLW D'32' ; LOAD MAXIMUM WAIT FOR SECOND PRESS TO
DINTERVAL
MOVWF DINTERVAL
CALL TIMER
CHECK2: BTFSC PORTB, 0 ; CHECK FOR SECOND PRESS
GOTO DECR2 ; WAIT FOR SECOND PRESS
MOVLW D'10' ; LOAD ENDDATAL WITH BLINK END DELAY TIME
MOVWF ENDDATAL
BSF PORTD, 4 ; INDICATE DOUBLE PRESS WITH LED 4 = ON
GOTO BLINK
Coursework - 1B : PIC16F887 Assembly Programming
13 | H63ECH - Embedded Computing Osama Azim
DECR2: CALL TIMER ; DECREMENT DINTERVAL FOR SECOND PRESS WAIT
DECFSZ DINTERVAL
GOTO CHECK2
GOTO BLINK ; RETURN TO BLINK IF NO SECOND PRESS
TIMER: BTFSS INTCON, T0IF ; WAIT FOR TIMER TO ROLL OVER
GOTO TIMER
BCF INTCON, T0IF ; CLEAR INTERRUPT FLAG
RETURN
DELAY130: MOVLW D'1' ; LOAD TIME MULTIPLYER TO TIME1
MOVWF TIME1
CALL TIMER
DECFSZ TIME1,F ; DECREMENT TIME1, RETURN IF ZERO
GOTO $-2
RETURN
DELAY260: MOVLW D'3'
MOVWF TIME1
CALL TIMER
DECFSZ TIME1,F
GOTO $-2
RETURN
DELAY520: MOVLW D'7'
MOVWF TIME1
CALL TIMER
DECFSZ TIME1,F
GOTO $-2
RETURN
DELAY1000: MOVLW D'15'
MOVWF TIME1
CALL TIMER
DECFSZ TIME1,F
GOTO $-2
RETURN
DELAY2000: MOVLW D'31'
MOVWF TIME1
CALL TIMER
DECFSZ TIME1,F
GOTO $-2
RETURN
END
Coursework - 1B : PIC16F887 Assembly Programming
14 | H63ECH - Embedded Computing Osama Azim
Appendix - iii : Coursework 1B-ii , Smart Power Socket, Assembly Code
#include <p16F887.inc>
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF &
_CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
cblock 0x20
COUNTD
BUTTOND
TIME
TIME1
DINTERVAL
endc
org 0
START: BSF STATUS,RP0 ; SELECT BANK 1
MOVLW B'00000111'
MOVWF OPTION_REG
MOVLW 0x01
MOVWF TRISB ; PORTB, PIN0 SET AS INPUT FOR SWITCH
MOVLW 0xFF
MOVWF TRISA ; PORT A IS ALL INPUT
CLRF TRISD ; PORT D IS ALL OUTPUT
MOVLW 0x00 ; Left Justified, Vdd-Vss referenced
MOVWF ADCON1
BSF STATUS,RP1 ; SELECT BANK 3
MOVLW 0x01 ; PORT A, PIN0 IS ANALOG
MOVWF ANSEL
MOVLW 0x00 ; PORT B, ALL PINS DIGITAL
MOVWF ANSELH
BCF STATUS,RP0 ; RETURN TO BANK 0
BCF STATUS,RP1
MOVLW 0X41
MOVWF ADCON0 ; A2D CLOCK SET TO Fosc/8, A2D CHANNEL 0
; SELECTED (RA0), TURN ON A2D MODULE
Coursework - 1B : PIC16F887 Assembly Programming
15 | H63ECH - Embedded Computing Osama Azim
CLRF ADRESH ; CLEAR/INITIALIZE REGISTERS
CLRF PORTD
CLRF TIME
CLRF TIME1
ON: CLRF PORTD
CALL DEBOUNCE1 ; CHECK DEBOUNCE, BUTTON PRESS
BTFSS BUTTOND,0 ; IF BUTTON PRESSED, GO TO CONVERT A2D
AND TURN LED ON
GOTO ON
ADC: NOP ; WAIT FOR BYPASS CAP TO SETTLE VOLTAGE
NOP
NOP
NOP
NOP
NOP
BSF ADCON0,GO_DONE ; START A2D CONVERSION
BTFSS ADCON0,GO_DONE ; CHECK IF CONVERSION DONE
GOTO $-1
MOVF ADRESH, W ; MOVE CONVERTED VALUE TO W
CN: XORLW 1 ; CHECK IF A2D CONVERSION IS 1, LESS THAN 0.625V
BTFSC STATUS, Z
GOTO LEDN ; RESET PORT D
C0: XORLW 32 ; CHECK IF A2D CONVERSION IS 32, 0.625V
BTFSC STATUS, Z
GOTO LED0 ; LED0 ON
C1: XORLW 63 ; CHECK IF A2D CONVERSION IS 63, 1.25V
BTFSC STATUS, Z
GOTO LED1 ; LED1 ON
C2: XORLW 96 ; CHECK IF A2D CONVERSION IS 96, 1.875V
BTFSC STATUS, Z
GOTO LED2 ; LED2 ON
C3: XORLW 128 ; CHECK IF A2D CONVERSION IS 128, 2.5V
BTFSC STATUS, Z
GOTO LED3 ; LED3 ON
C4: XORLW 160 ; CHECK IF A2D CONVERSION IS 160, 3.125V
BTFSC STATUS, Z
GOTO LED4 ; LED4 ON
C5: XORLW 191 ; CHECK IF A2D CONVERSION IS 191, 3.75V
BTFSC STATUS, Z
Coursework - 1B : PIC16F887 Assembly Programming
16 | H63ECH - Embedded Computing Osama Azim
GOTO LED5 ; LED5 ON
C6: XORLW 223 ; CHECK IF A2D CONVERSION IS 223, 4.37V
BTFSC STATUS, Z
GOTO LED6 ; LED6 ON
C7: XORLW 254 ; CHECK IF A2D CONVERSION IS 254, 5V
BTFSC STATUS, Z
GOTO LED7 ; LED7 ON
OFF: BTFSC PORTB,0 ; BUTTON PRESSED?
GOTO ADC ; GOTO CONVERTING A2D IF BUTTON NOT PRESSED
GOTO ON ; GOTO RESET PORT D AND WAIT FOR NEXT BUTTON PRESS
LEDN: CLRF PORTD
GOTO ADC
LED0: CLRF PORTD ; RESET PREVIOUS PORTD D VALUE, LED
BSF PORTD, 0 ; SET APPROPRIATE LED
GOTO ADC ; GOTO CONVERTING A2D
LED1: CLRF PORTD
BSF PORTD, 1
GOTO ADC
LED2: CLRF PORTD
BSF PORTD, 2
GOTO ADC
LED3: CLRF PORTD
BSF PORTD, 3
GOTO ADC
LED4: CLRF PORTD
BSF PORTD, 4
GOTO ADC
LED5: CLRF PORTD
BSF PORTD, 5
GOTO ADC
LED6: CLRF PORTD
BSF PORTD, 6
GOTO ADC
LED7: CLRF PORTD
BSF PORTD, 7
GOTO ADC
DEBOUNCE1: BTFSC PORTB, 0 ; CHECK IF BUTTON PRESSED
GOTO DEBOUNCE1
Coursework - 1B : PIC16F887 Assembly Programming
17 | H63ECH - Embedded Computing Osama Azim
CALL DELAY130 ; DELAY TO FILTER FALSE CLICKS
CLRW
INCF COUNTD ; INCREMENT DEBOUNCE COUNTS, TO
;B'00000001'
BTFSS PORTB, 0 ; CHECK IF BUTTON RELEASED
GOTO $-1
CALL DELAY130 ; DELAY TO FILTER FALSE RELEASE
MOVF COUNTD,W ; MOVE DEBOUNCE COUNT TO BITTOND. BUTTOND
;IS NOW B'00000001'
MOVWF BUTTOND
CLRF COUNTD ; CLEAR COUNTD REGISTER
RETURN ; RETURN FROM DEBOUNCE
TIMER: BTFSS INTCON, T0IF
GOTO TIMER
BCF INTCON, T0IF
RETURN
DELAY130: MOVLW D'1'
MOVWF TIME1
CALL TIMER
DECFSZ TIME1,F
GOTO $-2
RETURN
END

More Related Content

What's hot

Industrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsIndustrial training report of embedded system and robotics
Industrial training report of embedded system and robotics
Pallavi Bharti
 
Project Report On Micro-controller Embedded System
Project Report On Micro-controller Embedded SystemProject Report On Micro-controller Embedded System
Project Report On Micro-controller Embedded System
Rkrishna Mishra
 
Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming
Dr. Pankaj Zope
 
PLC presentation
PLC presentationPLC presentation
PLC presentation
Satyanand Chaudhary
 
imp plc-presentation-140205031532-phpapp02
imp plc-presentation-140205031532-phpapp02imp plc-presentation-140205031532-phpapp02
imp plc-presentation-140205031532-phpapp02
Haji Hussain
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentation
Roshit Kadiru
 
Programmable Logic Controllers Paper (PLC) SM54
Programmable Logic Controllers Paper (PLC) SM54Programmable Logic Controllers Paper (PLC) SM54
Programmable Logic Controllers Paper (PLC) SM54
Subhash Mahla
 
Embedded systems, 8051 microcontroller
Embedded systems, 8051 microcontrollerEmbedded systems, 8051 microcontroller
Embedded systems, 8051 microcontroller
Amandeep Alag
 
Introduction to embedded system
Introduction to embedded systemIntroduction to embedded system
Introduction to embedded system
Niteesh Srivastava
 
Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...
Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...
Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...
Living Online
 
Parking Control System using PLC
Parking Control System using PLCParking Control System using PLC
Parking Control System using PLC
ZunAib Ali
 
Microcontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay KumarMicrocontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay Kumar
Vijay Kumar
 
PLC - Programmable Logic Controller
PLC - Programmable Logic ControllerPLC - Programmable Logic Controller
PLC - Programmable Logic Controller
Mahesh Vadhavaniya profmjv
 
Programmable logic controllers
Programmable logic controllersProgrammable logic controllers
Programmable logic controllers
Naveen Chandrasekar
 
Introduction to plc (s7)­
Introduction to  plc (s7)­ Introduction to  plc (s7)­
Introduction to plc (s7)­
majitra
 
105996292 electrical-control-automation-studio
105996292 electrical-control-automation-studio105996292 electrical-control-automation-studio
105996292 electrical-control-automation-studio
Tùng Nguyễn
 
GOWTHAM REPORT
GOWTHAM REPORTGOWTHAM REPORT
GOWTHAM REPORT
gowtham sekar
 
Learn PLC Programming Free - A Beginners Guide
Learn PLC Programming Free - A Beginners GuideLearn PLC Programming Free - A Beginners Guide
Learn PLC Programming Free - A Beginners Guide
ACC Automation
 
Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200
Ahmed Elsayed
 
project report on embedded system
project report on embedded systemproject report on embedded system
project report on embedded system
ram avtar
 

What's hot (20)

Industrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsIndustrial training report of embedded system and robotics
Industrial training report of embedded system and robotics
 
Project Report On Micro-controller Embedded System
Project Report On Micro-controller Embedded SystemProject Report On Micro-controller Embedded System
Project Report On Micro-controller Embedded System
 
Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming
 
PLC presentation
PLC presentationPLC presentation
PLC presentation
 
imp plc-presentation-140205031532-phpapp02
imp plc-presentation-140205031532-phpapp02imp plc-presentation-140205031532-phpapp02
imp plc-presentation-140205031532-phpapp02
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentation
 
Programmable Logic Controllers Paper (PLC) SM54
Programmable Logic Controllers Paper (PLC) SM54Programmable Logic Controllers Paper (PLC) SM54
Programmable Logic Controllers Paper (PLC) SM54
 
Embedded systems, 8051 microcontroller
Embedded systems, 8051 microcontrollerEmbedded systems, 8051 microcontroller
Embedded systems, 8051 microcontroller
 
Introduction to embedded system
Introduction to embedded systemIntroduction to embedded system
Introduction to embedded system
 
Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...
Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...
Practical Programmable Logic Controllers (PLCs) for Automation and Process Co...
 
Parking Control System using PLC
Parking Control System using PLCParking Control System using PLC
Parking Control System using PLC
 
Microcontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay KumarMicrocontroller (8051) by K. Vijay Kumar
Microcontroller (8051) by K. Vijay Kumar
 
PLC - Programmable Logic Controller
PLC - Programmable Logic ControllerPLC - Programmable Logic Controller
PLC - Programmable Logic Controller
 
Programmable logic controllers
Programmable logic controllersProgrammable logic controllers
Programmable logic controllers
 
Introduction to plc (s7)­
Introduction to  plc (s7)­ Introduction to  plc (s7)­
Introduction to plc (s7)­
 
105996292 electrical-control-automation-studio
105996292 electrical-control-automation-studio105996292 electrical-control-automation-studio
105996292 electrical-control-automation-studio
 
GOWTHAM REPORT
GOWTHAM REPORTGOWTHAM REPORT
GOWTHAM REPORT
 
Learn PLC Programming Free - A Beginners Guide
Learn PLC Programming Free - A Beginners GuideLearn PLC Programming Free - A Beginners Guide
Learn PLC Programming Free - A Beginners Guide
 
Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200
 
project report on embedded system
project report on embedded systemproject report on embedded system
project report on embedded system
 

Viewers also liked

H64CSA_1B_023799_Osama
H64CSA_1B_023799_OsamaH64CSA_1B_023799_Osama
H64CSA_1B_023799_Osama
Osama Azim
 
H63ECH_1A_023799_Osama
H63ECH_1A_023799_OsamaH63ECH_1A_023799_Osama
H63ECH_1A_023799_Osama
Osama Azim
 
H64CSA_1A_023799_Osama
H64CSA_1A_023799_OsamaH64CSA_1A_023799_Osama
H64CSA_1A_023799_Osama
Osama Azim
 
Web based control
Web based controlWeb based control
Web based control
Osama Azim
 
Gregg Carlson report sample California LV Strip Sept 18
Gregg Carlson report sample California LV Strip Sept 18Gregg Carlson report sample California LV Strip Sept 18
Gregg Carlson report sample California LV Strip Sept 18
Gregg Carlson
 
Web based control of pressure loop apparatus
Web based control of pressure loop apparatusWeb based control of pressure loop apparatus
Web based control of pressure loop apparatus
Osama Azim
 
Class 3 control system components
Class 3   control system componentsClass 3   control system components
Class 3 control system components
Manipal Institute of Technology
 
Class 1 need for process control & process terminology
Class 1   need for process control & process terminologyClass 1   need for process control & process terminology
Class 1 need for process control & process terminology
Manipal Institute of Technology
 
Instrumentation and process control fundamentals
Instrumentation and  process control fundamentalsInstrumentation and  process control fundamentals
Instrumentation and process control fundamentals
hossam hassanein
 

Viewers also liked (9)

H64CSA_1B_023799_Osama
H64CSA_1B_023799_OsamaH64CSA_1B_023799_Osama
H64CSA_1B_023799_Osama
 
H63ECH_1A_023799_Osama
H63ECH_1A_023799_OsamaH63ECH_1A_023799_Osama
H63ECH_1A_023799_Osama
 
H64CSA_1A_023799_Osama
H64CSA_1A_023799_OsamaH64CSA_1A_023799_Osama
H64CSA_1A_023799_Osama
 
Web based control
Web based controlWeb based control
Web based control
 
Gregg Carlson report sample California LV Strip Sept 18
Gregg Carlson report sample California LV Strip Sept 18Gregg Carlson report sample California LV Strip Sept 18
Gregg Carlson report sample California LV Strip Sept 18
 
Web based control of pressure loop apparatus
Web based control of pressure loop apparatusWeb based control of pressure loop apparatus
Web based control of pressure loop apparatus
 
Class 3 control system components
Class 3   control system componentsClass 3   control system components
Class 3 control system components
 
Class 1 need for process control & process terminology
Class 1   need for process control & process terminologyClass 1   need for process control & process terminology
Class 1 need for process control & process terminology
 
Instrumentation and process control fundamentals
Instrumentation and  process control fundamentalsInstrumentation and  process control fundamentals
Instrumentation and process control fundamentals
 

Similar to H63ECH_1B_023799_OsamaAzim

A Computer Based Artificial Neural Network Controller with Interactive Audito...
A Computer Based Artificial Neural Network Controller with Interactive Audito...A Computer Based Artificial Neural Network Controller with Interactive Audito...
A Computer Based Artificial Neural Network Controller with Interactive Audito...
theijes
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
Electric&elctronics&engineeering
 
Embedded systems presentation
Embedded systems presentationEmbedded systems presentation
Embedded systems presentation
Surender Singh
 
ELE2303 Assign 1 Page 1 ELE2303 Embedded Systems Design.docx
ELE2303 Assign 1  Page  1 ELE2303 Embedded Systems Design.docxELE2303 Assign 1  Page  1 ELE2303 Embedded Systems Design.docx
ELE2303 Assign 1 Page 1 ELE2303 Embedded Systems Design.docx
jack60216
 
Industrial monitoring and control system using android application
Industrial monitoring and control system using android applicationIndustrial monitoring and control system using android application
Industrial monitoring and control system using android application
Avinash Vemula
 
Ht usb5130-v2
Ht usb5130-v2Ht usb5130-v2
Ht usb5130-v2
handson28
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
Susmit Sircar
 
Digital Alarm Clock 446 project report
Digital Alarm Clock 446 project reportDigital Alarm Clock 446 project report
Digital Alarm Clock 446 project report
Akash Mhankale
 
Real-Time Monitoring and Control System for Industry
Real-Time Monitoring and Control System for IndustryReal-Time Monitoring and Control System for Industry
Real-Time Monitoring and Control System for Industry
ijsrd.com
 
Smart home
Smart homeSmart home
Smart home
Moorthy kvn
 
Smart home copy
Smart home   copySmart home   copy
Smart home copy
Moorthy kvn
 
Smart home
Smart homeSmart home
Smart home
Moorthy kvn
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
Kavya Gupta
 
1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
mercysuttle
 
Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)
Siang Wei Lee
 
Door_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdfDoor_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdf
nyakmutia2
 
Home automation
Home automationHome automation
Home automation
Moorthy kvn
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
MeghdeepSingh
 
[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...
[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...
[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...
IJET - International Journal of Engineering and Techniques
 
Development Of An Internet Controlled Surveillance Mobile Robot Part1
Development Of An Internet Controlled Surveillance Mobile Robot Part1Development Of An Internet Controlled Surveillance Mobile Robot Part1
Development Of An Internet Controlled Surveillance Mobile Robot Part1
mimi
 

Similar to H63ECH_1B_023799_OsamaAzim (20)

A Computer Based Artificial Neural Network Controller with Interactive Audito...
A Computer Based Artificial Neural Network Controller with Interactive Audito...A Computer Based Artificial Neural Network Controller with Interactive Audito...
A Computer Based Artificial Neural Network Controller with Interactive Audito...
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
 
Embedded systems presentation
Embedded systems presentationEmbedded systems presentation
Embedded systems presentation
 
ELE2303 Assign 1 Page 1 ELE2303 Embedded Systems Design.docx
ELE2303 Assign 1  Page  1 ELE2303 Embedded Systems Design.docxELE2303 Assign 1  Page  1 ELE2303 Embedded Systems Design.docx
ELE2303 Assign 1 Page 1 ELE2303 Embedded Systems Design.docx
 
Industrial monitoring and control system using android application
Industrial monitoring and control system using android applicationIndustrial monitoring and control system using android application
Industrial monitoring and control system using android application
 
Ht usb5130-v2
Ht usb5130-v2Ht usb5130-v2
Ht usb5130-v2
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
 
Digital Alarm Clock 446 project report
Digital Alarm Clock 446 project reportDigital Alarm Clock 446 project report
Digital Alarm Clock 446 project report
 
Real-Time Monitoring and Control System for Industry
Real-Time Monitoring and Control System for IndustryReal-Time Monitoring and Control System for Industry
Real-Time Monitoring and Control System for Industry
 
Smart home
Smart homeSmart home
Smart home
 
Smart home copy
Smart home   copySmart home   copy
Smart home copy
 
Smart home
Smart homeSmart home
Smart home
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
 
1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
 
Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)
 
Door_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdfDoor_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdf
 
Home automation
Home automationHome automation
Home automation
 
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptxINDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
 
[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...
[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...
[IJET-V2I3P18] Authors: Mr. B. N. Patil , Mr. Sandesh Sonar , Mr. Pavankumar ...
 
Development Of An Internet Controlled Surveillance Mobile Robot Part1
Development Of An Internet Controlled Surveillance Mobile Robot Part1Development Of An Internet Controlled Surveillance Mobile Robot Part1
Development Of An Internet Controlled Surveillance Mobile Robot Part1
 

H63ECH_1B_023799_OsamaAzim

  • 1. Contents Page 1B-i: Heart Monitor 1 1B-ii: Smart Socket 5 Appendix-i: Subroutines 9 Appendix-ii: Assembly Code (1B-i) 10 Appendix-iii: Assembly Code (1B-ii) 14 H63ECH - Embedded Computing (AUT 15 -16) Coursework 1B PIC16F887 Assembly Programming Submitted By: Osama Azim (ID: 023799), M.Sc. Electronics Communication and Computer Engineering
  • 2. Coursework - 1B : PIC16F887 Assembly Programming 1 | H63ECH - Embedded Computing Osama Azim 1B-i : Heart Monitor o Introduction: With available on-board I/O's on the PIC Kit2 - one push button, eight LEDs - the coursework objectives resemble a simplified heart beat monitor. Following prominent features of a portable heart beat recorder/monitor were required to be developed on a PIC16F887 Microcontroller (MCU) in PIC Assembly language using the MPLAB assembler:  User identification stored in device memory and displayed - emulated by storing Student ID in MCU EEPROM and successful write operation indicated on LEDs  Device ready or in standby mode - emulated by signaling an LED on/off  Data-logging of heart beat sensor readings - emulated by blinking an LED intermittently  End of data-log - emulated by indicating appropriate LED sequence upon input from a pushbutton o State Diagram and Flow Charts: Above described coursework objectives can be represented by following state diagram: State actions: State Ready: LED 0 is turned ON, initially device enters State Ready by a pushbutton press after EEPROM data writing. State Datalog: LED 0 maintained ON while LED 1 blinks intermittently, next transition is upon a double click of pushbutton and further delay of 3 seconds. LED 4 turned on to indicate a double press and hold on time. State End: LED 0, LED 1 are turned OFF, LED 2 turned ON. Transition back to State Ready on Button press. Figure1: State diagram State Ready State DataLog ButtonPress = 0 ButtonPress = 1 Double Press = 1, Delay 3 sec. Button Double Press = 0 State End ButtonPress = 1 ButtonPress = 0
  • 3. Main Program Flow Chart No No No Write Student ID to EEPROM Start Debounce Button Press? Turn On LED 5,6,7 : from Port D Debounce State Ready: LED 0 ON, LED 2 OFF Button Press? State Datalog: LED 1 OFF Delay Decrement ENDATAL ENDDATAL = 1? State End: LED-2 ON, LED-0 OFF, LED-1 OFF, LED-4 OFF LED 1 ON Button Press? Delay Yes Yes Double Click Double Click? Load "10" To ENDDATAL Yes Yes No No Yes
  • 4. Coursework - 1B : PIC16F887 Assembly Programming 3 | H63ECH - Embedded Computing Osama Azim Flow Chart for Double Click: Notes on double click:  Hold time for continuous button press during LED 1 blink cycle can be adjusted by loading appropriate value to DINTERVAL (for max press time) register.  Second click wait time can also be adjusted similarly by loading an appropriate value to DINTERVAL after first click release Yes From Main Program Flow Yes Load DINTERVAL (For maximum second click wait time) No DINTERVAL = 0 ? No Load DINTERVAL (For maximum press time) Timer Button Press? Decrement DINTERVAL State Datalog: Blink Routine Button Press? Yes No Timer Button Press? Load ENDDATAL, LED-4 ON Yes Decrement DINTERVAL DINTERVAL = 0 ? No Yes No
  • 5. Coursework - 1B : PIC16F887 Assembly Programming 4 | H63ECH - Embedded Computing Osama Azim o Discussion and Conclusion: All coursework objectives were realized with certain modifications and known issues, these are noted in following points:  A debounce subroutine was developed to filter out unwanted, noise like, pushbutton transitions during button press. This subroutine, although effective, was not extensively optimized and a more efficient debounce logic can be developed.  The transition hold time of 3 seconds from State DataLog to State End is indicated by LED 4 being turned ON, this also indicates a successful double press. Though not essential, this feature was implemented for a better device state indication - as the double click can often be disregarded due to exit from second click hold time or short successive click interval.  Upon detecting a click in between of State Datalog blink loop, LED 1 is maintained ON until a second click is detected or maximum wait time for second click is reached, whichever occurs earlier. The program developed could not check for double click while blinking LED 1 simultaneously, but the LED 1 hold ON time during double click subroutine can be reduced by adjusting the wait time for second click. Conclusion and Learning outcome:  Programming with a lower level language, assembly, is directly dependent on the target CPU/MCU. This is in contrast with higher level languages like C - for which the compiler provides an illusion of codes being generic for multiple machine architectures.  Considering that every CPU/MCU is designed with their respective assembly instructions, programs written in assembly for a specific architecture is more robust when compared to a higher level language.  Due to its hardware dependent nature, optimum hardware utilization can be achieved by programming in assembly. This is especially useful for embedded applications, wherein a CPU/MCU is dedicated to execute predetermined tasks, keeping cost of hardware down along with achieving a higher degree of reliability.
  • 6. Coursework - 1B : PIC16F887 Assembly Programming 5 | H63ECH - Embedded Computing Osama Azim 1B-ii : Smart Power Socket Introduction: As described in the Coursework-1A report, the Smart Power Socket was conceptualized as an IoT device with IP based remote switching and monitoring. The features realized using the provided PIC16F887 MCU based PIC Kit 2 development board:  A Button Press emulates the remote command to switch device On/Off. With an initial press of pushbutton, appropriate LED is turned On or Off.  Current consumed by appliance is emulated by varying the voltage supplied to MCU ADC through the onboard potentiometer. Usage of ADC : The PIC16F887 ADC is configured with following parameters:  Port: PORT A, PIN 0  Channel: RA 0 - ADC channel 0  ADC voltage reference: Positive: Vdd, Negative: Vss  ADC conversion clock: Fosc/8  Result Formatting: Left Justified The conversion process is executed in following steps: Figure 1: ADC conversion TAD Cycles The output result format used is left justified, the ADRESH register that holds the conversion result has following structure:
  • 7. Coursework - 1B : PIC16F887 Assembly Programming 6 | H63ECH - Embedded Computing Osama Azim Figure 2: ADRESH register format The ADC conversion result is calculated using the formula: ADC = VIN/VREF * 1023 The application designed for this coursework turns ON a respective LED in accordance to the voltage level converted at the ADC. The PIC Kit 2 development board has 8 LEDs connected to PORT D. Considering an input voltage range of 0V to 5V, each LED is stepped on a voltage of 0.625V (5V/8). The reference ADRESH value to stitch LEDs is calculated below: LED ON Voltage In (v) ADC Value Binary Decimal Ref (ADRESH) 0 0.625 128 00100000 00 32 1 1.25 255 00111111 11 63 2 1.875 384 01100000 00 96 3 2.5 512 10000000 00 128 4 3.125 640 10100000 00 160 5 3.75 767 10111111 11 191 6 4.37 894 11011111 10 223 7 ~5 1019 11111110 11 254 o State Diagram and Flow Chart: The program toggles between two states as explained below: State OFF: All LEDs turned OFF, wait for push button to transition to State ON. State ON: Capture ADC value and turn ON respective LED to signify voltage level. Next press of Pushbutton makes the transition back to State OFF. Figure1: State diagram State OFF ButtonPress = 0 State ON ButtonPress = 1 ButtonPress = 0 ButtonPress = 1
  • 8. Coursework - 1B : PIC16F887 Assembly Programming 7 | H63ECH - Embedded Computing Osama Azim Flow Chart for Smart Plug: Start Move ADRESH to W Yes Delay Cycle for Capacitor Start A2D Conversion A2D Done? Debounce Button Press? Yes No No Button Press? Yes Clear PORT D - All LEDs Off No YesADRESH = "x" Volt Level? No "x" matching LED = ON Clear PORT D
  • 9. Coursework - 1B : PIC16F887 Assembly Programming 8 | H63ECH - Embedded Computing Osama Azim o Discussion and Conclusion: Known Issues:  After successive On/Off transitions, the LEDs were found not to turn on by press of pushbutton, and would turn on only after a change in potentiometer value. Design Limitations and Conclusion: Achieving complex design objectives, such as IoT based control, through Assembly is a lengthy process which would require extensive effort - these objectives can be achieved with relative ease through higher level programming languages. The focus of this coursework was not to implement a feature heavy design, but to understand the various machine level operations such as calculated usage of ADC or utilization of MCU timers, for example. Assembly programming, as its uniquely defined for each device, enables complete hardware usage of target CPU/MCU - this allows for an in depth understanding of the various computing and peripheral components that make up a MCU. Although assembly codes are not suitable for real world applications today, knowledge of the underlying hardware and understanding of the "assembly program development approach" would encourage programmers to develop efficient programs in higher level languages as well.
  • 10. Coursework - 1B : PIC16F887 Assembly Programming 9 | H63ECH - Embedded Computing Osama Azim Appendix - i : Subroutines Subroutines used at multiple instances in Coursework: COUNTD: B7 B6 B5 B4 B3 B2 B1 B0 x x x x x x x 1/0 Appropriate COUNTD bit can be tested for required delay to achieve debounce Flow Chart for Timer Subroutine: Using: Overflow time = 4 * (1/Fosc) * Prescale * (256-TMR 0) We have: Overflow Time = 6.55 x 10-2 sec Flow Chart for Delay subroutine: Delay = (6.55 x 10-2 Sec) * (2X ) Flow Chart for Debounce Subroutine: Yes Timer Timer Rolled Over? No Clear Interrupt Flag RETURN No Delay "x" ms TIME1 =0? RETURN Yes Move Time Multiplier to TIME1 Timer Decrement Time Multiplier Moved to BUTTOND, and B0 tested for denounced Press Move COUNTD to BUTTOND Yes Debounce Button Press? No Delay Increment COUNTD Button Release? No Yes Delay Clear COUNTD RETURN
  • 11. Coursework - 1B : PIC16F887 Assembly Programming 10 | H63ECH - Embedded Computing Osama Azim Appendix - ii : Coursework 1B-i , Heart Beat Monitor, Assembly Code #include <p16F887.inc> __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT __CONFIG _CONFIG2, _WRT_OFF & _BOR21V cblock 0x20 COUNTD BUTTOND TCOUNT TIME TIME1 COUNTER DINTERVAL ENDDATAL endc org 0 START: BSF STATUS, RP0 ;SELECT BANK 1 MOVLW B'00000111' ; CONFIGURE TIMER0 PRESCALER BITS MOVWF OPTION_REG ; MOVE TO OPTION REG MOVLW 0x01 MOVWF TRISB ; PORTB, PIN0 SET AS INPUT FOR SWITCH CLRF TRISD ; PORTD SET TO ALL OUTPUTS FOR LEDs BSF STATUS, RP1 ; SELECT REGISTER BANK 3 MOVLW 0X00 MOVWF ANSELH ; PORTB PINS SET AS DIGITAL INPUT BCF STATUS, RP0 ; SELECT REGISTER BANK 0 BCF STATUS, RP1 CLRF PORTD ; INITIALIZE PORTD AS ALL OFF (LEDs) CLRF COUNTD ; CLEAR GPR DATA CLRF BUTTOND CLRF COUNTER CLRF TCOUNT CLRF TIME CLRF ENDDATAL
  • 12. Coursework - 1B : PIC16F887 Assembly Programming 11 | H63ECH - Embedded Computing Osama Azim BSF STATUS, RP1 ; SELECT BANK 2 MOVLW D'99' ; DECIMAL 99, LAST DIGITS OF STUDENT ID:023799 MOVWF EEDATA ; LOAD TO EEDATA MOVLW 0x20 ; EEPROM ADDRESS MOVWF EEADR BSF STATUS, RP0 ; SELECT BANK 3 BSF EECON1, 2 ; WRITE ENABLE FOR EEPROM BCF INTCON, 7 ; DISABLE GLOBAL INTERRUPTS MOVLW 0x55 ; SAFETY PROCEDURE MOVWF EECON2 MOVLW 0xAA MOVWF EECON2 BSF EECON1, 1 ; START WRITING BCF STATUS, RP0 ; SELECT BANK 0 BCF STATUS, RP1 BSF PORTD, 5 ; LED 5, 6, 7 ON TO INDICATE WRITE COMPLETE BSF PORTD, 6 BSF PORTD, 7 S_READY: CALL DEBOUNCE1 ; CHECK DEBOUNCE, BUTTON PRESS BTFSS BUTTOND, 0 ; BUTTON PRESS? GOTO S_READY BSF PORTD, 0 ; INDICATE STATE READY BCF PORTD, 2 ; CLEAR INDICATION FOR STATE END S_DATALOG: CALL DEBOUNCE1 ; CHECK DEBOUNCE, BUTTON PRESS BTFSS BUTTOND, 0 ; BUTTON PRESS? GOTO S_DATALOG BLINK: BCF PORTD, 1 ; START BLINK, LED 1 = OFF CALL DELAY260 ; LED 1 OFF DELAY DECF ENDDATAL ; CHECK IF DATALOG STATE NEEDS TO END, ;DECREMENT ENDDATAL REGISTER MOVF ENDDATAL, W ; CHECK IF ENDDATAL HAS REACHED 1 XORLW 1 BTFSC STATUS, Z ; IF YES, GOTO STATE END GOTO S_END BSF PORTD, 1 ; BLINK, LED 1 = ON CALL DELAY260 ; LED 1 ON DELAY BTFSC PORTB, 0 ; CHECK IF BUTTON IS PRESSED GOTO BLINK ; IF NOT, LOOP BLINK
  • 13. Coursework - 1B : PIC16F887 Assembly Programming 12 | H63ECH - Embedded Computing Osama Azim GOTO DOUBLEC ; IF YES, CHECK FOR DOUBLE CLICK S_END: CLRF ENDDATAL ; CLEAR ENDDATAL REGISTER BSF PORTD, 2 ; INDIACATE STATE END BY LED 2 = ON BCF PORTD, 0 ; TURN OFF OTHER LEDs BCF PORTD, 1 BCF PORTD, 4 CALL DELAY1000 GOTO S_READY ; GO TO STATE READY, CHEC FOR NEXT ; BUTTON PRESS DEBOUNCE1: BTFSC PORTB, 0 ; CHECK IF BUTTON PRESSED GOTO DEBOUNCE1 CALL DELAY130 ; DELAY TO FILTER FALSE CLICKS CLRW INCF COUNTD ; INCREMENT DEBOUNCE COUNTS, TO ; B'00000001' BTFSS PORTB, 0 ; CHECK IF BUTTON RELEASED GOTO $-1 CALL DELAY130 ; DELAY TO FILTER FALSE RELEASE MOVF COUNTD,W ; MOVE DEBOUNCE COUNT TO BITTOND. BUTTOND ; IS NOW B'00000001' MOVWF BUTTOND CLRF COUNTD ; CLEAR COUNTD REGISTER RETURN ; RETURN FROM DEBOUNCE DOUBLEC: MOVLW D'3' ; LOAD MAXIMUM PRESS DELAY TO DINTERVAL MOVWF DINTERVAL CALL DELAY520 BTFSC PORTB, 0 ; BUTTON STILL PRESSED? GOTO CHECK ; IF NOT, CHECK FOR SECOND PRESS DECR1: CALL TIMER ; DECREMENT MAXIMUM PRESS COUNT DECFSZ DINTERVAL GOTO DECR1 GOTO BLINK ; RETURN TO BLINK CHECK: MOVLW D'32' ; LOAD MAXIMUM WAIT FOR SECOND PRESS TO DINTERVAL MOVWF DINTERVAL CALL TIMER CHECK2: BTFSC PORTB, 0 ; CHECK FOR SECOND PRESS GOTO DECR2 ; WAIT FOR SECOND PRESS MOVLW D'10' ; LOAD ENDDATAL WITH BLINK END DELAY TIME MOVWF ENDDATAL BSF PORTD, 4 ; INDICATE DOUBLE PRESS WITH LED 4 = ON GOTO BLINK
  • 14. Coursework - 1B : PIC16F887 Assembly Programming 13 | H63ECH - Embedded Computing Osama Azim DECR2: CALL TIMER ; DECREMENT DINTERVAL FOR SECOND PRESS WAIT DECFSZ DINTERVAL GOTO CHECK2 GOTO BLINK ; RETURN TO BLINK IF NO SECOND PRESS TIMER: BTFSS INTCON, T0IF ; WAIT FOR TIMER TO ROLL OVER GOTO TIMER BCF INTCON, T0IF ; CLEAR INTERRUPT FLAG RETURN DELAY130: MOVLW D'1' ; LOAD TIME MULTIPLYER TO TIME1 MOVWF TIME1 CALL TIMER DECFSZ TIME1,F ; DECREMENT TIME1, RETURN IF ZERO GOTO $-2 RETURN DELAY260: MOVLW D'3' MOVWF TIME1 CALL TIMER DECFSZ TIME1,F GOTO $-2 RETURN DELAY520: MOVLW D'7' MOVWF TIME1 CALL TIMER DECFSZ TIME1,F GOTO $-2 RETURN DELAY1000: MOVLW D'15' MOVWF TIME1 CALL TIMER DECFSZ TIME1,F GOTO $-2 RETURN DELAY2000: MOVLW D'31' MOVWF TIME1 CALL TIMER DECFSZ TIME1,F GOTO $-2 RETURN END
  • 15. Coursework - 1B : PIC16F887 Assembly Programming 14 | H63ECH - Embedded Computing Osama Azim Appendix - iii : Coursework 1B-ii , Smart Power Socket, Assembly Code #include <p16F887.inc> __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT __CONFIG _CONFIG2, _WRT_OFF & _BOR21V cblock 0x20 COUNTD BUTTOND TIME TIME1 DINTERVAL endc org 0 START: BSF STATUS,RP0 ; SELECT BANK 1 MOVLW B'00000111' MOVWF OPTION_REG MOVLW 0x01 MOVWF TRISB ; PORTB, PIN0 SET AS INPUT FOR SWITCH MOVLW 0xFF MOVWF TRISA ; PORT A IS ALL INPUT CLRF TRISD ; PORT D IS ALL OUTPUT MOVLW 0x00 ; Left Justified, Vdd-Vss referenced MOVWF ADCON1 BSF STATUS,RP1 ; SELECT BANK 3 MOVLW 0x01 ; PORT A, PIN0 IS ANALOG MOVWF ANSEL MOVLW 0x00 ; PORT B, ALL PINS DIGITAL MOVWF ANSELH BCF STATUS,RP0 ; RETURN TO BANK 0 BCF STATUS,RP1 MOVLW 0X41 MOVWF ADCON0 ; A2D CLOCK SET TO Fosc/8, A2D CHANNEL 0 ; SELECTED (RA0), TURN ON A2D MODULE
  • 16. Coursework - 1B : PIC16F887 Assembly Programming 15 | H63ECH - Embedded Computing Osama Azim CLRF ADRESH ; CLEAR/INITIALIZE REGISTERS CLRF PORTD CLRF TIME CLRF TIME1 ON: CLRF PORTD CALL DEBOUNCE1 ; CHECK DEBOUNCE, BUTTON PRESS BTFSS BUTTOND,0 ; IF BUTTON PRESSED, GO TO CONVERT A2D AND TURN LED ON GOTO ON ADC: NOP ; WAIT FOR BYPASS CAP TO SETTLE VOLTAGE NOP NOP NOP NOP NOP BSF ADCON0,GO_DONE ; START A2D CONVERSION BTFSS ADCON0,GO_DONE ; CHECK IF CONVERSION DONE GOTO $-1 MOVF ADRESH, W ; MOVE CONVERTED VALUE TO W CN: XORLW 1 ; CHECK IF A2D CONVERSION IS 1, LESS THAN 0.625V BTFSC STATUS, Z GOTO LEDN ; RESET PORT D C0: XORLW 32 ; CHECK IF A2D CONVERSION IS 32, 0.625V BTFSC STATUS, Z GOTO LED0 ; LED0 ON C1: XORLW 63 ; CHECK IF A2D CONVERSION IS 63, 1.25V BTFSC STATUS, Z GOTO LED1 ; LED1 ON C2: XORLW 96 ; CHECK IF A2D CONVERSION IS 96, 1.875V BTFSC STATUS, Z GOTO LED2 ; LED2 ON C3: XORLW 128 ; CHECK IF A2D CONVERSION IS 128, 2.5V BTFSC STATUS, Z GOTO LED3 ; LED3 ON C4: XORLW 160 ; CHECK IF A2D CONVERSION IS 160, 3.125V BTFSC STATUS, Z GOTO LED4 ; LED4 ON C5: XORLW 191 ; CHECK IF A2D CONVERSION IS 191, 3.75V BTFSC STATUS, Z
  • 17. Coursework - 1B : PIC16F887 Assembly Programming 16 | H63ECH - Embedded Computing Osama Azim GOTO LED5 ; LED5 ON C6: XORLW 223 ; CHECK IF A2D CONVERSION IS 223, 4.37V BTFSC STATUS, Z GOTO LED6 ; LED6 ON C7: XORLW 254 ; CHECK IF A2D CONVERSION IS 254, 5V BTFSC STATUS, Z GOTO LED7 ; LED7 ON OFF: BTFSC PORTB,0 ; BUTTON PRESSED? GOTO ADC ; GOTO CONVERTING A2D IF BUTTON NOT PRESSED GOTO ON ; GOTO RESET PORT D AND WAIT FOR NEXT BUTTON PRESS LEDN: CLRF PORTD GOTO ADC LED0: CLRF PORTD ; RESET PREVIOUS PORTD D VALUE, LED BSF PORTD, 0 ; SET APPROPRIATE LED GOTO ADC ; GOTO CONVERTING A2D LED1: CLRF PORTD BSF PORTD, 1 GOTO ADC LED2: CLRF PORTD BSF PORTD, 2 GOTO ADC LED3: CLRF PORTD BSF PORTD, 3 GOTO ADC LED4: CLRF PORTD BSF PORTD, 4 GOTO ADC LED5: CLRF PORTD BSF PORTD, 5 GOTO ADC LED6: CLRF PORTD BSF PORTD, 6 GOTO ADC LED7: CLRF PORTD BSF PORTD, 7 GOTO ADC DEBOUNCE1: BTFSC PORTB, 0 ; CHECK IF BUTTON PRESSED GOTO DEBOUNCE1
  • 18. Coursework - 1B : PIC16F887 Assembly Programming 17 | H63ECH - Embedded Computing Osama Azim CALL DELAY130 ; DELAY TO FILTER FALSE CLICKS CLRW INCF COUNTD ; INCREMENT DEBOUNCE COUNTS, TO ;B'00000001' BTFSS PORTB, 0 ; CHECK IF BUTTON RELEASED GOTO $-1 CALL DELAY130 ; DELAY TO FILTER FALSE RELEASE MOVF COUNTD,W ; MOVE DEBOUNCE COUNT TO BITTOND. BUTTOND ;IS NOW B'00000001' MOVWF BUTTOND CLRF COUNTD ; CLEAR COUNTD REGISTER RETURN ; RETURN FROM DEBOUNCE TIMER: BTFSS INTCON, T0IF GOTO TIMER BCF INTCON, T0IF RETURN DELAY130: MOVLW D'1' MOVWF TIME1 CALL TIMER DECFSZ TIME1,F GOTO $-2 RETURN END