I am working on a tutorial from Gooligum about this light meter on Lesson 10 example 2 and my resources have been running out. I have been doing the exercises like lighting the LED, flashing, counters and so on but this one puzzles me. If I power up the first digit transistor, I can see 1 on the display. It seems that my multiplexing program does'nt work. Can anyone please enlighten me on this? I am a newbie and I know I have missed something here. Attached were the drawing and the code.
Mod edit: code tags
Code:
;**********************************************************************
; Description: *
; Display Light Meter on 2 digit seven segment display *
; MPLABXIDE Version 3.26 *
; MPASMWIN (v5.66) *
;**********************************************************************
; *
; Filename: LightDisp.asm *
; Date: September 11, 2016 *
; File Version: 0.01 *
; *
; Author: Nestor Bulala *
; Company: Seven Net *
; *
; *
;**********************************************************************
; *
; Notes: *
; Pin Assignment: *
; AN2 (pin 11) = voltage to be measured ( LDR) *
; RB0-1, RB4, RC1-4 = 7 segment display bus ( common cathode) *
; RC5 (pin 5) = "tens" digit enable ( active high) *
; RB5 (pin 2) = "ones" digit enable (active high) *
;**********************************************************************
list p=16F506 ; list directive to define processor
#include <p16F506.inc> ; processor specific variable definitions
radix dec
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC_RB4EN & _IOSCFS_OFF
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
; pin assignments
#define TENS PORTC,5 ; "tens" digit enable
#define ONES PORTB,2 ; "ones" digit enable
;***** VARIABLE DEFINITIONS
UDATA_SHR
temp RES 1 ; used by set7seg routine (temp digit store)
;**********************************************************************
;*********** RC CALIBRATION
RCCAL CODE 0x3FF ; processor reset vector
res 1 ; holds internal RC cal value as a movlw k
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
;************RESET VECTOR *********************************************
RESET CODE 0x000 ; effective reset vector
movwf OSCCAL ; apply internal RC factory calibration
pagesel start
goto start ; jump to main code
;***** Subroutine vectors
set7seg ; display digit on 7-segment display
pagesel set7seg_R
goto set7seg_R
;***** MAIN PROGRAM ***************************************************
MAIN CODE
;***** Initialisation
start
; configure ports
clrw ; configure PORTB and PORTC as all outputs
tris PORTB
tris PORTC
clrf CM1CON0 ; disable comparator 1, RB0, RB1 digital
clrf CM2CON0 ; disable comparator 2, RC0, RC1 digital
clrf VRCON ; disable CVref, RC2 usable
; configure ADC
movlw b'01111001' ; configure ADC:
; 01------ AN2 (only) analog (ANS = 01)
; --11---- clock = INTOSC/4 (ADCS = 11)
; ----10-- select channel AN2 (CHS = 10)
; -------1 turn ADC on (ADON = 1)
movwf ADCON0 ; AN2 ready for sampling
; configure timer
movlw b'11010111' ; configure Timer0:
; --0----- timer mode (TOCS = 0), RC5 usable
; ----0--- prescaler assigned to Timer0 (PSA = 0)
; -----111 prescale = 256 (PS = 111)
option ; increment every 256 us
; (TMR0 2 cycles every 2.048 ms)
;***** MAIN LOOP
main_loop
; sample input
bsf ADCON0,GO ; start conversion
w_adc btfsc ADCON0,NOT_DONE ; wait until conversion complete
goto w_adc
; display high nibble for 2.048 ms
w10_hi btfss TMR0,2 ; wait for TMR0 2 to go high
goto w10_hi
swapf ADRES,w ; get "tens" digit
andlw 0x0F ; from high nibble of ADC result
pagesel set7seg
call set7seg ; then output it
pagesel $
bsf TENS ; enable "tens" display
w10_lo btfsc TMR0,2 ; wait for TMR0 2 to go low
goto w10_lo
; display ones for 2.048 ms
w1_hi btfss TMR0,2 ; wait for TMR0 2 to go high
goto w1_hi
movf ADRES,w ; get ones digit
andlw 0x0F ; from low nibble of ADC result
pagesel set7seg
call set7seg ; then output it
pagesel $
bsf ONES ; enable "ones" display
w1_lo btfsc TMR0,2 ; wait for TMR0 2 to go low
goto w1_lo
; repeat forever
goto main_loop
;***** LOOKUP TABLES ***********************************************
TABLES CODE 0x200 ; locate at beginning of a page
; pattern table for 7 segment display on PORTB
; RB4 = E, RB1:0 = FG
get7sB addwf PCL,f
retlw b'010010' ; 0
retlw b'000000' ; 1
retlw b'010001' ; 2
retlw b'000001' ; 3
retlw b'000011' ; 4
retlw b'000011' ; 5
retlw b'010011' ; 6
retlw b'000000' ; 7
retlw b'010011' ; 8
retlw b'000011' ; 9
retlw b'010011' ; A
retlw b'010011' ; b
retlw b'010010' ; C
retlw b'010001' ; d
retlw b'010011' ; E
retlw b'010011' ; F
; pattern table for 7 segment display on port C
; RC4:1 = CDBA
get7sC addwf PCL,f
retlw b'011110' ; 0
retlw b'010100' ; 1
retlw b'001110' ; 2
retlw b'011110' ; 3
retlw b'010100' ; 4
retlw b'011010' ; 5
retlw b'011010' ; 6
retlw b'010110' ; 7
retlw b'011110' ; 8
retlw b'011110' ; 9
retlw b'010110' ; A
retlw b'011000' ; b
retlw b'001010' ; C
retlw b'011100' ; d
retlw b'001010' ; E
retlw b'000010' ; F
; Display digit passed in W on 7 segment display
set7seg_R
; disable displays
clrf PORTB ; clear all digit enable lines on PORTB
clrf PORTC ; and PORT C
; output digit pattern
movwf temp ; save digit
call get7sB ; lookup pattern for port B
movwf PORTB ; then output it
movf temp,w ; get digit
call get7sC ; then repeat for port C
movwf PORTC
retlw 0
END
Attachments
-
6.5 KB Views: 9
-
73.7 KB Views: 12
Last edited by a moderator: