• AVR Freaks

Helpful ReplyHot!How to make PIC18F458-based Digital Voltmeter using assembly language?

Author
vicky99
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/11/27 04:12:04
  • Location: 0
  • Status: offline
2019/11/27 09:28:08 (permalink)
0

How to make PIC18F458-based Digital Voltmeter using assembly language?

I need to make a pic18 based voltmeter. But I couldnt find any assembly language codes for this task. I need to perform ADC and print the result in two 8bit led display. One led should display the voltage and the other should display the decimal value of that voltage. Kindly help me with this project. How to print this decimal value to the LEDs?
Given Task:
a) Assemble the PIC18F assembly language programs using the MPLAB.
b) Using a proper programmer, download the HEX code into the PIC18F458 on the breadboard from your Personal Computer or Laptop.
c) Use the default clock of the PIC18F458 and connect the appropriate RESET circuit to the PIC18F458 MCLR pin.
d) On the bread board, connect the hardware to the PIC18F458, and demonstrate your design as a stand-alone system.
#1
ric
Super Member
  • Total Posts : 27968
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/11/27 19:10:53 (permalink)
+3 (3)
Assuming you have downloaded the latest copy of MPLABX, and you want to work in Absolute mode.
Look in C:\Program Files (x86)\Microchip\MPLABX\v5.30\mpasmx\templates\Code\18F458TEMP.ASM
for an empty "template" file for your PIC.
 
Plainly this is a school assignment, so no-one is going to do all the work for you.
 
The very first step is to add some code to the template to try to turn one of the LEDS off and on once a second.
This will establish that your PIC is running, and at the speed you expect.
 
You have given no indication of what experience level you have already.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
vicky99
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/11/27 04:12:04
  • Location: 0
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 02:24:44 (permalink)
0
I have coded to perform ACD with interrupt. Now i need to transfer the data to two 7-Segment LED display. I am connecting my LED pins to Port C and Port D. How do I program to transfer the recieved byte from ADRESL and ADRESH to LED display?
My code for ADC with interrupt is given below:
LIST P=PIC18F458
#include P18F458.INC
ORG 0000H
GOTO MAIN
ORG 0008H
BTFSS PIR1, ADIF
RETFIE
GOTO AD_ISR
ORG 00100H
MAIN CLRF TRISC
CLRF TRISD
BSF TRISA, 0
MOVLW 81H
MOVWF ADCON0
MOVLW 0CEH
MOVWF ADCON1
BCF PIR1, ADIF
BSF PIE1, ADIE
BSF INTCON, PEIE
BSF INTCON, GIE
OVER CALL DELAY
BSF ADCON0, GO
BRA OVER

AD_ISR
ORG 200H
MOVFF ADRESL, PORTC
MOVFF ADRESH, PORTD

BCF PIR1, ADIF
RETFIE
END
 
Kindly help me how to code to send the HByte and LByte data to 7- segment led display
post edited by vicky99 - 2019/12/08 03:39:18
#3
ric
Super Member
  • Total Posts : 27968
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 02:45:45 (permalink)
+1 (1)
How about some comments to tell us what you think the code is doing?
There was really no need to use an interrupt service at all, you could have just polled the GO bit in this simple code.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
vicky99
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/11/27 04:12:04
  • Location: 0
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 03:04:51 (permalink)
0
Hi. Thank you for your reply. It is my school assignment. We have to use the interrupt service routine to get the analog data and convert.
With BSF ADCON0, GO I have called the start and End of conversion. it basically gets the Analog input and converts it, once converted it tells the CPU to proceed to next operation.
Here is the rough flow of the code:
1. Bypass the interrupt vectore
2. define i/p and o/p
3. load ADCON0 and ADCON1
4. Enabling Interrupts
5. start conversion and wait for EOC
6. give low byte to Port C and Hight Byte to Port D
 
Now these low byte and high byte has to be sent to two 7segment LED Dispay. I am too new to PIC. I was just studying for like 2 months about embedded systems. 
 
Thank you
 
#5
teenix
Junior Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2017/12/21 13:47:21
  • Location: Australia, Melbourne
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 03:30:10 (permalink) ☄ Helpfulby vicky99 2019/12/08 05:24:18
+1 (1)
MOVFF ADRESL, PORTC
MOVFF ADRESL, PORTD


 
You are moving the same value to both ports.
This will only display binary data to the 7 segment display, which you will have to interpret somehow.
 
To show ADRESL in decimal will require 3 LED displays. Eg 0 - 255.
Two displays will do for a hexadecimal display Eg 00 - FF
 
You could use a simple table to decode data for a hexadecimal display.
Assuming segments GFEDCBA are PORTC and PORTD bits 6543210 then something like...
 
    swapf ADRESL,W      ; get A2DL result hi nibble
    call to7seg
    movwf PORTC
    movf ADRESL,W      ; get A2DL result lo nibble
    call to7seg
    movwf PORTD    
 
; -----------------------------------
; SUBROUTINE: CONVERT 4 BIT NIBBLE TO 7 SEGMENT DISPLY VALUE
; input value in W
to7seg     andlw 0x0F
               addwf PCL
               retlw b'00111111'   ; 0
               retlw b'00000110'   ; 1
               ....etc
               retlw b'01110001'   ; F
; -----------------------------------
 
Note that this is simplified code and will need alterations to work properly, but may give some ideas.
 
Converting a binary value to BCD is more difficult, but the same LED table can be used for each of the 3 BCD nibbles a subroutine of this nature would produce.
 
cheers
 
Tony
 
post edited by teenix - 2019/12/08 03:44:34
#6
ric
Super Member
  • Total Posts : 27968
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 03:35:41 (permalink)
+1 (1)
vicky99
Hi. Thank you for your reply. It is my school assignment. We have to use the interrupt service routine to get the analog data and convert.

Are you saying that the assignment specifically requirss you to read the ADC inside an interrupt service?
 

With BSF ADCON0, GO I have called the start and End of conversion. it basically gets the Analog input and converts it, once converted it tells the CPU to proceed to next operation.
Here is the rough flow of the code:
1. Bypass the interrupt vectore
2. define i/p and o/p
3. load ADCON0 and ADCON1
4. Enabling Interrupts
5. start conversion and wait for EOC
6. give low byte to Port C and Hight Byte to Port D

Comments go IN THE CODE adjacent to the lines you are commenting on. Not in a separate post.
 

Now these low byte and high byte has to be sent to two 7segment LED Dispay. I am too new to PIC. I was just studying for like 2 months about embedded systems. 

Even if you display in hex, you need two 7 segment displays for EACH byte.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
vicky99
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/11/27 04:12:04
  • Location: 0
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 04:03:03 (permalink)
0
teenix
MOVFF ADRESL, PORTC
MOVFF ADRESL, PORTD


 
You are moving the same value to both ports.
This will only display binary data to the 7 segment display, which you will have to interpret somehow.
 

 
Sorry I made a typo. i changed it now (its ADRESH and ADRESL) . And I am using two 7seg LEDdisplays. Its a voltmeter with range 0-10V.
I donot understand what you mean by ADDWF PCL. What is PCL here?
 
ric
 
 
Are you saying that the assignment specifically requirss you to read the ADC inside an interrupt service?
 

Yes. I need to use interrupt.
 
Can you be more clear on how to transfer my data from ADRESH and ADRESL to my two LED DISPLAYS please?
 
Thank you
#8
ric
Super Member
  • Total Posts : 27968
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 04:19:54 (permalink)
+2 (2)
There are more details you have to work out yourself.
How are you going to measure up to 10V, when the maximum voltage you can input to the PIC is the same as the PIC's power supply?
You will HAVE to reduce the incoming voltage.
 
The ADC gives you a 10 bit value which indicates the ratio of the measured voltage to the ADC's reference voltage.
If you want to display this in volts, then you need to work out how to scale this to get an integer from 0 to 10, then how to convert this to the values required to drive those 7 segment LED modules.
This is all pretty basic stuff, but we're not here to give you the answers on a plate.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#9
vicky99
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/11/27 04:12:04
  • Location: 0
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 04:36:07 (permalink)
0
ric
There are more details you have to work out yourself.
How are you going to measure up to 10V, when the maximum voltage you can input to the PIC is the same as the PIC's power supply?
You will HAVE to reduce the incoming voltage.
 
The ADC gives you a 10 bit value which indicates the ratio of the measured voltage to the ADC's reference voltage.
If you want to display this in volts, then you need to work out how to scale this to get an integer from 0 to 10, then how to convert this to the values required to drive those 7 segment LED modules.
This is all pretty basic stuff, but we're not here to give you the answers on a plate.
 




Yes I have made considerations on Vin, Vref stuffs that are necessary to convert. 
I am only unsure how I send the data from ADRESH and ADRESL to the LED Pins. The LED has a common voltage source. So I should code convert the value in the inverse of the binary digit (ex 1100 001 for 0.)
It would be nice if you could give a very brief explanation on sending data to led display
#10
ric
Super Member
  • Total Posts : 27968
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 04:52:57 (permalink)
+2 (2)
You have not told me exactly what the display is.
if it's just an ordinary 7 segment display, then it is YOUR JOB to work out which LEDS have to be energised to display a "0", which LEDs to display a "1", and so on for all ten possible digits.
Plainly some sort of lookup table is the easiest way to do it, so you have to figure out how to implement a lookup table.
teenix pretty much gave you the necessary code.
 
The missing link is how to scale the ADC value to the voltage. Mathematical calculation are not that simple in assembly language, (they are trivial in C). {
Plainly your teacher wants you to figure out how to do it, or maybe they expect to arrange your hardware to make the scaling much easier...
 
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#11
hudejun
Electrical engineer
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/12/05 08:48:06
  • Location: 0
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 05:45:26 (permalink)
0
Just follow datasheet.
 
1. Configure the A/D module:
• Configure analog pins, voltage reference and digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit
3. Wait the required acquisition time.
4. Start conversion:
• Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
OR
• Waiting for the A/D interrupt
 
PIC18 provides very simple asm instructions.
And you will need to use only BSF or BCF to set/clear ADC register flags.
#12
teenix
Junior Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2017/12/21 13:47:21
  • Location: Australia, Melbourne
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 06:04:27 (permalink)
0
> I donot understand what you mean by ADDWF PCL. What is PCL here?
 
PCL is Program Counter Low. Modifying this register changes the Program Counter. You need to consider the PCLATH and perhaps PCLATU registers as well.
 
There will probably be a section in the data sheet "Look up tables in program memory". Worth a look.
 
Check out interrupts "Context Saving" in the data sheet too :-)
 
cheers
Tony
 
post edited by teenix - 2019/12/08 06:08:38
#13
dan1138
Super Member
  • Total Posts : 3713
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 15:47:59 (permalink)
+1 (1)
@vicky99,

The members here have offered several good suggestions, but these suggests will confuse someone with limited experiences of PIC assembly language.

Here is code that will setup TIMER0 to assert an interrupt about every millisecond then start an ADC conversion:
;
; Filename: main.asm
; Date: 2019-Dec-8
; Author: dan1138
; Target: PIC18F458
;
; Files required: P18F458.INC
; 18F458_G.LKR generic linker script
;
; Description:
;
;
list n=0,c=255,r=dec ; this makes the .LST look pretty
;
; PIC18F458
; +---------:_:---------+
; ICD_VPP VPP -> : 1 MCLRn PGD 40 : <> RB7 ICD_PGD
; ANALOG_IN RA0 <> : 2 AN0 PGC 39 : <> RB6 ICD_PGC
; RA1 <> : 3 AN1 PGM 38 : <> RB5
; RA2 <> : 4 AN2 37 : <> RB4
; RA3 <> : 5 AN3 36 : <> RB3
; RA4 <> : 6 INT2 35 : <> RB2
; RA5 <> : 7 AN4 INT1 34 : <> RB1
; RE0 <> : 8 AN5 INT0 33 : <> RB0
; RE1 <> : 9 AN6 32 : <- VDD
; RE2 <> : 10 AN7 31 : <- VSS
; VDD -> : 11 30 : <> RD7 SEG-DPn
; VSS -> : 12 29 : <> RD6 SEG-An
; 8MHz XTAL RA7 <> : 13 OSC1 28 : <> RD5 SEG-Bn
; 8MHz XTAL RA6 <> : 14 OSC2 27 : <> RD4 SEG-Cn
; DIGIT_1n RC0 <> : 15 T1OSO RXD 26 : <> RC7
; DIGIT_2n RC1 <> : 16 T1OSI TXD 25 : <> RC6
; DIGIT_3n RC2 <> : 17 24 : <> RC5
; DIGIT_4n RC3 <> : 18 23 : <> RC4
; SEG-Gn RD0 <> : 19 22 : <> RD3 SEG-Dn
; SEG-Fn RD1 <> : 20 21 : <> RD2 SEG-En
; +---------------------+
; DIP-40
;
include "p18F458.inc"

; CONFIG1H
CONFIG OSC = HS ; Oscillator Selection bits (HS oscillator)
CONFIG OSCS = OFF ; Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))

; CONFIG2L
CONFIG PWRT = OFF ; Power-up Timer Enable bit (PWRT disabled)
CONFIG BOR = OFF ; Brown-out Reset Enable bit (Brown-out Reset disabled)
CONFIG BORV = 25 ; Brown-out Reset Voltage bits (VBOR set to 2.5V)

; CONFIG2H
CONFIG WDT = OFF ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
CONFIG WDTPS = 128 ; Watchdog Timer Postscale Select bits (1:128)

; CONFIG4L
CONFIG STVR = ON ; Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause Reset)
CONFIG LVP = OFF ; Low-Voltage ICSP Enable bit (Low-Voltage ICSP disabled)

; CONFIG5L
CONFIG CP0 = OFF ; Code Protection bit (Block 0 (000200-001FFFh) not code protected)
CONFIG CP1 = OFF ; Code Protection bit (Block 1 (002000-003FFFh) not code protected)
CONFIG CP2 = OFF ; Code Protection bit (Block 2 (004000-005FFFh) not code protected)
CONFIG CP3 = OFF ; Code Protection bit (Block 3 (006000-007FFFh) not code protected)

; CONFIG5H
CONFIG CPB = OFF ; Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
CONFIG CPD = OFF ; Data EEPROM Code Protection bit (Data EEPROM not code protected)

; CONFIG6L
CONFIG WRT0 = OFF ; Write Protection bit (Block 0 (000200-001FFFh) not write protected)
CONFIG WRT1 = OFF ; Write Protection bit (Block 1 (002000-003FFFh) not write protected)
CONFIG WRT2 = OFF ; Write Protection bit (Block 2 (004000-005FFFh) not write protected)
CONFIG WRT3 = OFF ; Write Protection bit (Block 3 (006000-007FFFh) not write protected)

; CONFIG6H
CONFIG WRTC = OFF ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
CONFIG WRTB = OFF ; Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
CONFIG WRTD = OFF ; Data EEPROM Write Protection bit (Data EEPROM not write protected)

; CONFIG7L
CONFIG EBTR0 = OFF ; Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
CONFIG EBTR1 = OFF ; Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
CONFIG EBTR2 = OFF ; Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
CONFIG EBTR3 = OFF ; Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)

; CONFIG7H
CONFIG EBTRB = OFF ; Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)

;*******************************************************************************
; System constants
;*******************************************************************************
; System oscillator frequency:
#define FSY (8000000)

; Instruction cycle frequency:
#define FCY (FSY/4)

;*******************************************************************************
; Reset Vector
;*******************************************************************************
RES_VECT CODE 0x0000 ; processor reset vector
GOTO START ; go to beginning of program

ISRHV CODE 0x0008
GOTO HIGH_ISR

;*******************************************************************************
; Interrupt Service Context save memory for Low Priority interrupt vector
;*******************************************************************************
ISRLD UDATA_ACS ; Space in the (ACCESS) bank common to all banks memory
WREG_SAVE RES 1
STATUS_SAVE RES 1
BSR_SAVE RES 1

;*******************************************************************************
; Data for LED segment refresh interrupt handler
;*******************************************************************************
LED_DATA UDATA_ACS ; Space in the (ACCESS) bank common to all banks memory
LED_SEGMENTS RES 4

;*******************************************************************************
; Interrupt Service Handler for Low Priority interrupt vector
;*******************************************************************************
ISRLV CODE 0x0018
LOW_ISR:
movwf WREG_SAVE
movff STATUS,STATUS_SAVE
movff BSR,BSR_SAVE
;
; Handle ADC interrupt
;
btfsc PIE1,ADIE
btfss PIR1,ADIF
bra ADC_exit
bcf PIR1,ADIF

; Read left justified ADC value from ADRESH:ADRESL

ADC_exit:

; <Insert Low Priority ISR handlers Here>

movff BSR_SAVE,BSR
movf WREG_SAVE,W
movff STATUS_SAVE,STATUS
RETFIE
;
;*******************************************************************************
; Startup code to initialize this PIC
;*******************************************************************************
START:
clrf INTCON
clrf INTCON3
clrf PIE1
clrf PIE2
clrf PIE3
bsf RCON,IPEN

movlw 0x07
movwf CMCON

clrf LATA
clrf LATB
movlw 0x0F
movWf LATC
setf LATD
clrf LATE

movlw 0x01
movwf TRISA
clrf TRISB
clrf TRISC
clrf TRISD
bcf TRISE,TRISE0
bcf TRISE,TRISE1
bcf TRISE,TRISE2

clrf ADCON0
movlw 0x0E
movwf ADCON1
bsf ADCON0,ADON
bcf IPR1,ADIP
bcf PIR1,ADIF
bsf PIE1,ADIE

clrf T0CON
movlw 0x42
movwf T0CON
bsf INTCON2,TMR0IP
bcf INTCON,T0IF
bsf INTCON,T0IE
bsf T0CON,TMR0ON

setf LED_SEGMENTS+0
setf LED_SEGMENTS+1
setf LED_SEGMENTS+2
setf LED_SEGMENTS+3

bsf INTCON,GIEL
bsf INTCON,GIEH

goto main

;*******************************************************************************
; Interrupt Service Handler for High Priority interrupt vector
;*******************************************************************************
ISRH CODE ; let linker place high ISR routine
HIGH_ISR:
;
; Handle TIMER0 interrupt
;
btfsc INTCON,T0IE
btfss INTCON,T0IF
bra TMR0_exit
bcf INTCON,T0IF
;
; Refresh 4-digits of LED segments
;
movlw 0x0F
btfss LATC,LATC3
bra LED_DO_Digit2
btfss LATC,LATC2
bra LED_DO_Digit1
btfss LATC,LATC1
bra LED_DO_Digit0
LED_DO_Digit3:
iorwf LATC,F
movf LED_SEGMENTS+3,W
movwf LATD
bcf LATC,LATC3
bra LED_Exit
LED_DO_Digit2:
iorwf LATC,F
movf LED_SEGMENTS+2,W
movwf LATD
bcf LATC,LATC2
bra LED_Exit
LED_DO_Digit1:
iorwf LATC,F
movf LED_SEGMENTS+1,W
movwf LATD
bcf LATC,LATC1
bra LED_Exit
LED_DO_Digit0:
iorwf LATC,F
movf LED_SEGMENTS+0,W
movwf LATD
bcf LATC,LATC0
LED_Exit:
;
btfsc ADCON0,GO ; If an ADC conversion is not in progress
bra TMR0_exit ; and the ADC interrupt is enabled
btfsc PIE1,ADIE ; and the interrupt request is not asserted
btfsc PIR1,ADIF ;
bra TMR0_exit ;
bsf ADCON0,GO ; request a start ADC conversion.
TMR0_exit:

; <Insert High Priority ISR handlers Here - WREG, STATUS, BSR context saved/restored by hardware>

RETFIE FAST

;*******************************************************************************
; MAIN PROGRAM
;*******************************************************************************
MAIN_PROG CODE
;
; Main Application
;
main:

; <Insert Your Application initialization calls here>

;
; Main Application process loop
;
main_loop:

; <Insert Your Process calls here>

GOTO main_loop ; loop forever

END

The ADC interrupt handler is not complete.
You will need to scale the raw ADC counts to your require voltage display range.
Then convert the scaled raw ADC value to LED segments for display.
The code to scale the raw ADC value and convert it to LED segments is not provided.

The tasks left for you to solve are:

1) How to connect a common anode 4-digit LED display module using 4 PNP transistor as digit drivers to PORTC.
2) How to connect the segments of the LED display module with series resistors to limit current to PORTD.
3) How to read the raw ADC conversion value and scale to your required voltage display range.
4) Convert this value to LED segment ON/OFF states for each digit of the display.

Is is up to you to decide if this code is any use for your project.

In the end you can run this code with the MPLAB simulator so you can observe how priority interrupts work with the PIC18F458 controller.

As you do not like to put useful comment in your code I have left out most of those from my code too. 

<EDIT>

Here is a schematic:
post edited by dan1138 - 2019/12/09 21:44:59

Attached Image(s)

#14
PStechPaul
Super Member
  • Total Posts : 2810
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: How to make PIC18F458-based Digital Voltmeter using assembly language? 2019/12/08 18:56:27 (permalink)
+2 (2)
With an internet search, you should be able to find quite a few projects and tutorials about driving seven segment LEDs. Here are some I found, although they may not be exactly what you want. And that is good, because the object of your assignment is to learn how to figure out things on your own, with maybe just a little help.
 
https://circuitdigest.com/microcontroller-projects/7-segment-display-interfacing-with-pic16f877a/
 
http://www.idc-online.com/technical_references/pdfs/electronic_engineering/Multiplexing_7_segment_display_using_PIC_microcontroller.pdf
 
http://www.learningaboutelectronics.com/Articles/PIC16F690-7-segment-LED-display-circuit.php
 
https://theembeddedlab.com/tutorials/interfacing-7-segment-display-pic16f-microcontroller/
 
https://www.egr.msu.edu/classes/ece480/capstone/fall08/group01/Doc/Vinod%20Application%20Note.pdf
 
https://bradsprojects.com/pic-assembly-tutorial-5-interfacing-seven-segment-displays/
 
Most, but not all, use "C" for the firmware. I assume that assembly language is required by the instructor, so you will need to follow the logic of the code and translate it to assembly.
 
Also, please use [ code] [ /code] tags around your code so it is easier to read. Post the complete code for your project, with comments describing what you are trying to do. Learn to use the simulator so you can trace through execution and evaluate contents of GPRs and SFRs (variables and control/status bytes). Good luck!

 
#15
Jump to:
© 2020 APG vNext Commercial Version 4.5