Frankie Chan
Hamdi Karkat
Table of Contents
1
Table of Contents........................................................................................................................ 1
Objective...................................................................................................................................... 3
Equipment................................................................................................................................ 3
Description................................................................................................................................... 3
Data............................................................................................................................................. 3
Assembly program...............................................................................................................3-6
Result………………………………………………………………………………………………………8
Conclusion................................................................................................................................... 9
2
Objective
The main objective of this lab is to understand the basic concepts of using a
Equipment
1. PIC Microcontroller
2. MPLAB
3. PIC 18 EXPLORER BOARD
Description
Using the pic 18 explorer board and part of their demo program we will be
implementing a program that displays a voltmeter using the center tap of R3 which is
connected to RA0, the A/D converter converts this analog voltage and the result is
displayed on the LCD in a range from 0 to 5v. We then display Temperature using the
MCP9701A analog thermal sensor. Then a clock which is a real-time function. When the
mode is entered, time begins at 00:00:00, the user can also set the time if desired. The
Program
#ifdef __18F8722
list p=18F8722
#include p18F8722.inc
CONFIG OSC = HSPLL
CONFIG FCMEN = OFF
CONFIG IESO = OFF
3
CONFIG PWRT = OFF
CONFIG BOREN = OFF
CONFIG WDT = OFF
CONFIG MCLRE = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
#endif
#ifdef __18F87J11
list p=18F8722
#include p18F87J11.inc
CONFIG FOSC = HSPLL
CONFIG STVREN = OFF,XINST = OFF,WDTEN = OFF,CP0 = OFF,FCMEN =
OFF,IESO = OFF
CONFIG MODE = MM
#endif
variables UDATA_ACS
ptr_pos RES 1
ptr_count RES 1
temp_1 RES 1
temp_2 RES 1
temp_3 RES 1
cmd_byte RES 1
temperature RES 1
LSD RES 1
MsD RES 1
MSD RES 1
seconds RES 1
minutes RES 1
hours RES 1
NumH RES 1
NumL RES 1
TenK RES 1
Thou RES 1
Hund RES 1
Tens RES 1
Ones RES 1
4
adr RES 1
dat RES 1
STARTUP CODE 0
NOP
goto start
NOP
NOP
NOP
PROG1 CODE
start
#ifdef __18F8722
movlw b'00001110' ;RA0 = analog input
movwf ADCON1
#endif
#ifdef __18F87J11
bsf WDTCON,ADSHR ;Shared SFR
setf ANCON0
setf ANCON1
bcf ANCON1,0 ;Make RA0 Analog input
bcf WDTCON,ADSHR
#endif
5
;Introduction
movlw .80 ;send "Microchip PICDEM" to LCD
movwf ptr_pos
call stan_char_1
menu
6
movlw .64 ;Display "RB0=Now RA5=Next"
movwf ptr_pos
call stan_char_2
t_wait
btfss select ;Check temperature
bra temp ;YES
btfsc scroll ;Goto Next
bra t_wait ;NO
c_wait
btfss select ;Goto Time
bra clock ;YES
btfsc scroll ;Go back to Main menu
bra c_wait
;*******************************************************************
#ifdef __18F8722
clrf ADCON0
bsf ADCON0,0 ;turn on A/D
7
movlw b'10111010'; ;right Justified Fosc/32
movwf ADCON2
#endif
#ifdef __18F87J11
clrf ADCON0
bsf ADCON0,0 ;turn on A/D
#endif
#ifdef __18F8722
movlw .49 ;ADC voltage steps 5V/1023
#endif
#ifdef __18F87J11
movlw .32 ;ADC voltage steps
3.3V/1023
#endif
movwf ARG2L
clrf ARG2H
call Mul16
movff RES0,AARGB1
movff RES1,AARGB0
8
call LCDLine_2 ;display A/D result on 2nd line
movf Hund,W ;get hunds
call bin_bcd
movf LSD,W ;send high digit from the LSD #.xx
movwf temp_wr
call d_write
movlw A'.' ;send decimal point "."
movwf temp_wr
call d_write
9
movlw A't'
movwf temp_wr
call d_write
movlw 0x20 ;2 spaces
movwf temp_wr
call d_write
movlw 0x20
movwf temp_wr
call d_write
#ifdef __18F8722
bsf ADCON0,0 ;turn on A/D
bsf ADCON0,CHS0 ;Channel1
#ifdef __18F87J11
clrf ADCON0
bsf ADCON0,0 ;turn on A/D
bsf ADCON0,CHS0 ;Channel 1
tempnew
10
bsf ADCON0,GO ;start conversion
btfsc ADCON0,GO
bra $-2
movff ADRESL,ARG1L
movff ADRESH,ARG1H
#ifdef __18F8722
movlw .49 ;ADC voltage steps
#endif
#ifdef __18F87J11
movlw .32
#endif
movwf ARG2L
clrf ARG2H
call Mul16
movff RES0,AARGB1
movff RES1,AARGB0
btfss STATUS,C
decf AARGB0
movlw 0x0F ;for 400mv for 9701A(0x0FA0)
subwf AARGB0,f
movf AARGB1,w
call bin_bcd
call LCDLine_1
movlw A'T' ;send "Temp=" to LCD
movwf temp_wr
call d_write
movlw A'e'
movwf temp_wr
call d_write
movlw A'm'
movwf temp_wr
call d_write
movlw A'p'
movwf temp_wr
call d_write
11
movlw 0x20 ;space
movwf temp_wr
call d_write
movlw A'='
movwf temp_wr
call d_write
movlw A'='
movwf temp_wr
call d_write
NOP
call delay_100ms
12
menu_clock1 ;Write the temperature to
eeprom
call InitEEprom
call WriteEEprom
bra menu_clock
clock
call delay_1s
btfss select ;wait for RB0 release
bra $-2
movf minutes,W
sublw .60
btfss STATUS,Z ;increment hours ?
bra clk_done
incf hours,F
clrf minutes
movf hours,W
sublw .13
btfss STATUS,Z
bra clk_done
movlw .1 ;start a new 12 hour period
movwf hours
clk_done
movf hours,W ;send hours to LCD
call bin_bcd
13
movf LSD,W ;send low digit
movwf temp_wr
call d_write
movlw 0x3A ;send : colon
movwf temp_wr
call d_write
return
;*******************************************************************
14
InitEEprom
bcf EEPROM_CS_TRIS
call InitSPI
bsf EEPROM_CS
return
ReadEEprom
bcf EEPROM_CS
movlw 0x03
movwf SSPBUF
call Check
movlw 0x00
movwf SSPBUF
call Check
movf adr,w
movwf SSPBUF
call Check
movlw 0x00
movwf SSPBUF
btfss PIR1,SSPIF
goto $-2
bcf PIR1,SSPIF
; movff SSPBUF,LATD
movf SSPBUF,w
bsf EEPROM_CS
return
WriteEEprom
bcf EEPROM_CS
movlw 0x06 ;Write Latch enable
movwf SSPBUF
call Check
bsf EEPROM_CS
call Delay
bcf EEPROM_CS
movlw 0x02 ;Write command
movwf SSPBUF
call Check
movlw 0x00 ;Read from Address
movwf SSPBUF
call Check
movlw 0x00
movwf SSPBUF
call Check
15
call Check
bsf EEPROM_CS
return
stan_next_char_1
tblrd *+
movff TABLAT,temp_wr
call d_write ;send character to LCD
return
16
movlw LOW stan_table
movwf TBLPTRL
movf ptr_pos,W
addwf TBLPTRL,F
clrf WREG
addwfc TBLPTRH,F
addwfc TBLPTRU,F
stan_next_char_2
tblrd *+
movff TABLAT,temp_wr
call d_write ;send character to LCD
return
;----------------------------------------------------------------------
d100l1
decfsz temp_1,F
bra d100l1
decfsz temp_2,F
bra d100l1
return
17
;---------------- 1s Delay -----------------------------------
delay_1s
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
call Ldelay
return
18
bra next_digit
clrf hours ;YES, reset hours to 00
next_digit
btfss scroll ;move to next digit
bra inc_mins
movf hours,W
bra set_time_again
inc_mins
btfss scroll ;wait for RA5 button release
bra $-2
call LCDLine_1
movlw 0x14 ;shift cursor to right 3 places
movwf temp_wr
call i_write
movlw 0x14
movwf temp_wr
call i_write
movlw 0x14
movwf temp_wr
call i_write
19
movwf temp_wr
call d_write
movf LSD,W ;send ones digit
movwf temp_wr
call d_write
movlw 0x3A ;send : colon
movwf temp_wr
call d_write
bra inc_mins
set_time_done
btfss scroll ;wait for RA5 button release
bra $-2
bra overflow
20
; TenK:Thou:Hund:Tens:Ones
swapf NumH,W
andlw 0x0F
addlw 0xF0
movwf Thou
addwf Thou,F
addlw 0xE2
movwf Hund
addlw 0x32
movwf Ones
movf NumH,W
andlw 0x0F
addwf Hund,F
addwf Hund,F
addwf Ones,F
addlw 0xE9
movwf Tens
addwf Tens,F
addwf Tens,F
swapf NumL,W
andlw 0x0F
addwf Tens,F
addwf Ones,F
rlcf Tens,F
rlcf Ones,F
comf Ones,F
rlcf Ones,F
movf NumL,W
andlw 0x0F
addwf Ones,F
rlcf Thou,F
movlw 0x07
movwf TenK
21
decf TenK,F
addwf Thou,F
btfss STATUS,C
bra Lb4
3.73V as a
retlw 0
result of placing
;********************************************************************* the 10k resistor
@ 5v and RA0,
RESULTS: A 10kohms
RA0 is centered
tapped to pot
Resistor @
R3
5v to RA0
Voltmeter Results
22
08:45:46
Time clock at
different times.
09:30:12
09:29:12
23
24
42 degree
Celcius at the
time of picture
Conclusion:
This project was tough and without Prof. Khader giving me the permission to use assembly and
with the help of the PIC community including some of the demo programs that was available this
project wouldn’t have been able to accomplish on time. We took the voltmeter source code from
25
an online site found on google. With that we were able to integrate that to the rest of the lab.
The temperature was easy to do since we already have a MCP9701A analog thermal sensor on
board. This project was suppose to be written in C but since none of us are proficient in C
language we chose to do it in assembly. Assembly is tedious and within this upcoming year we
are dedicating ourselves to learning how to program in C and learning the syntax.
26