Mosaic
Well-Known Member
16f886 PIC @ 8Mhz.
I have this modified BASIC tut program which works in Oshonsoft but the hex file produces gibberish in Proteus using the LM016L LCD module. This module works fine with Nigel's ASM LCD tut.
Proteus layout image attached, and here is the asm file that Oshon created that produces the gibberish in Proteus
Any advice as to what's going on is appreciated!!
I have this modified BASIC tut program which works in Oshonsoft but the hex file produces gibberish in Proteus using the LM016L LCD module. This module works fine with Nigel's ASM LCD tut.
Code:
Define ADC_CLOCK = 3 'default value is 3
Define ADC_SAMPLEUS = 20 'default value is 20
Define LCD_BITS = 4 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_EREG = PORTB
Define LCD_EBIT = 1
Define LCD_RWREG = 0 'portc 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0 '2 'set to 0 if not used, 0 is default
'Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
'Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
'Define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
Dim an0 As Word
AllDigital
TRISA = 0xff 'set all PORTA pins as inputs
ADCON1 = 0 'set all PORTA pins as analog inputs
Lcdinit 1 'initialize LCD module; cursor is blinking
loop:
Adcin 0, an0
Lcdcmdout LcdClear 'clear LCD display
Lcdout "Analog input AN0" 'text for the line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout "Value: ", #an0 'formatted text for line 2
WaitMs 100
Goto loop 'loop forever
Proteus layout image attached, and here is the asm file that Oshon created that produces the gibberish in Proteus
Code:
list p=16f886
#include <p16f886.inc>
radix dec
; Compiled with: PIC Simulator IDE v6.91
; Microcontroller model: PIC16F886
; Clock frequency: 8.0 MHz
;
; The address of 'an0' (word) (global) is 0x35
an0 EQU 0x35
; Begin
R0L EQU 0x20
R0H EQU 0x21
R1L EQU 0x22
R1H EQU 0x23
R2L EQU 0x24
R2H EQU 0x25
R3L EQU 0x26
R3H EQU 0x27
R4L EQU 0x28
R4H EQU 0x29
R5L EQU 0x2A
R5H EQU 0x2B
ORG 0x0000
BCF PCLATH,3
BCF PCLATH,4
GOTO L0002
ORG 0x0004
RETFIE
; Begin of program
L0002:
; 1: Define ADC_CLOCK = 3 'default value is 3
; 2: Define ADC_SAMPLEUS = 20 'default value is 20
; 3: Define LCD_BITS = 4 'allowed values are 4 and 8 - the number of data interface lines
; 4: Define LCD_DREG = PORTB
; 5: Define LCD_DBIT = 4 '0 or 4 for 4-bit interface, ignored for 8-bit interface
; 6: Define LCD_RSREG = PORTB
; 7: Define LCD_RSBIT = 0
; 8: Define LCD_EREG = PORTB
; 9: Define LCD_EBIT = 1
; 10: Define LCD_RWREG = 0 'portc 'set to 0 if not used, 0 is default
; 11: Define LCD_RWBIT = 0 '2 'set to 0 if not used, 0 is default
; 12: 'Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
; 13: 'Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
; 14: 'Define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100
; 15: 'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
; 16:
; 17: Dim an0 As Word
; 18: AllDigital
BSF STATUS,RP0
BSF STATUS,RP1
CLRF 0x08
CLRF 0x09
BCF STATUS,RP1
BCF STATUS,RP0
; 19: TRISA = 0xff 'set all PORTA pins as inputs
MOVLW 0xFF
BSF STATUS,RP0
MOVWF 0x05
; 20: ADCON1 = 0 'set all PORTA pins as analog inputs
CLRF 0x1F
BCF STATUS,RP0
; 21: Lcdinit 1 'initialize LCD module; cursor is blinking
BCF PORTB,1
BCF PORTB,0
BSF STATUS,RP0
BCF TRISB,1
BCF TRISB,0
MOVLW 0x0F
ANDWF TRISB,F
MOVLW 0x64
BCF STATUS,RP0
MOVWF R0L
CLRF R0H
CALL W001
MOVLW 0x33
CALL LC02
MOVLW 0x33
CALL LC02
MOVLW 0x33
CALL LC02
MOVLW 0x22
CALL LC02
MOVLW 0x28
CALL LC02
MOVLW 0x0D
CALL LC02
MOVLW 0x01
CALL LC02
; 22:
; 23: loop:
L0001:
; 24: Adcin 0, an0
BSF STATUS,RP0
BSF ADCON1,ADFM
BCF STATUS,RP0
CLRF R0L
CALL A001
BSF STATUS,RP0
MOVF ADRESL,W
BCF STATUS,RP0
MOVWF 0x35
MOVF ADRESH,W
MOVWF 0x36
; 25: Lcdcmdout LcdClear 'clear LCD display
MOVLW 0x01
CALL LC02
; 26: Lcdout "Analog input AN0" 'text for the line 1
MOVLW 0x41
CALL LC01
MOVLW 0x6E
CALL LC01
MOVLW 0x61
CALL LC01
MOVLW 0x6C
CALL LC01
MOVLW 0x6F
CALL LC01
MOVLW 0x67
CALL LC01
MOVLW 0x20
CALL LC01
MOVLW 0x69
CALL LC01
MOVLW 0x6E
CALL LC01
MOVLW 0x70
CALL LC01
MOVLW 0x75
CALL LC01
MOVLW 0x74
CALL LC01
MOVLW 0x20
CALL LC01
MOVLW 0x41
CALL LC01
MOVLW 0x4E
CALL LC01
MOVLW 0x30
CALL LC01
; 27: Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
MOVLW 0xC0
CALL LC02
; 28: Lcdout "Value: ", #an0 'formatted text for line 2
MOVLW 0x56
CALL LC01
MOVLW 0x61
CALL LC01
MOVLW 0x6C
CALL LC01
MOVLW 0x75
CALL LC01
MOVLW 0x65
CALL LC01
MOVLW 0x3A
CALL LC01
MOVLW 0x20
CALL LC01
MOVF 0x35,W
MOVWF 0x32
MOVF 0x36,W
MOVWF 0x33
CALL _append_lab_0001
CALL LC21
; 29: WaitMs 100 'larger value should be used in real device
MOVLW 0x64
MOVWF R0L
CLRF R0H
CALL W001
; 30: Goto loop 'loop forever
GOTO L0001
; End of program
L0003: GOTO L0003
; Waitms Routine
W001: MOVF R0L,F
BTFSC STATUS,Z
GOTO W002
CALL W003
DECF R0L,F
NOP
NOP
NOP
NOP
NOP
GOTO W001
W002: MOVF R0H,F
BTFSC STATUS,Z
RETURN
CALL W003
DECF R0H,F
DECF R0L,F
GOTO W001
W003: MOVLW 0x0C
MOVWF R2H
W004:
DECFSZ R2H,F
GOTO W004
NOP
NOP
MOVLW 0x26
MOVWF R1L
W005:
DECFSZ R1L,F
GOTO W006
CALL W007
CALL W007
NOP
NOP
RETURN
W006:
CALL W007
GOTO W005
W007: MOVLW 0x0D
MOVWF R2L
W008:
DECFSZ R2L,F
GOTO W008
NOP
RETURN
; Waitus Routine Byte
X001: MOVLW 0x05
SUBWF R4L,F
BTFSS STATUS,C
RETURN
GOTO X002
X002: MOVLW 0x03
SUBWF R4L,F
BTFSS STATUS,C
RETURN
GOTO X002
; Waitus Routine Word
Y001: MOVLW 0x08
SUBWF R4L,F
CLRW
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETURN
GOTO Y002
Y002: MOVLW 0x05
SUBWF R4L,F
CLRW
BTFSS STATUS,C
ADDLW 0x01
SUBWF R4H,F
BTFSS STATUS,C
RETURN
GOTO Y002
; Word Division Routine
D001: MOVLW 0x10
MOVWF R3L
CLRF R2H
CLRF R2L
D002: RLF R0H,W
RLF R2L,F
RLF R2H,F
MOVF R1L,W
SUBWF R2L,F
MOVF R1H,W
BTFSS STATUS,C
INCFSZ R1H,W
SUBWF R2H,F
BTFSC STATUS,C
GOTO D003
MOVF R1L,W
ADDWF R2L,F
MOVF R1H,W
BTFSC STATUS,C
INCFSZ R1H,W
ADDWF R2H,F
BCF STATUS,C
D003: RLF R0L,F
RLF R0H,F
DECFSZ R3L,F
GOTO D002
RETURN
; Adcin Routine
A001: RLF R0L,F
RLF R0L,F
MOVLW 0x3C
ANDWF R0L,F
MOVLW 0xC1
IORWF R0L,W
MOVWF ADCON0
MOVLW 0x14
MOVWF R4L
CALL X001
BSF ADCON0,GO
A002:
BTFSC ADCON0,GO
GOTO A002
BCF PIR1,ADIF
BCF ADCON0,ADON
RETURN
; Lcdout Routine
LC01: MOVWF R4L
BSF PORTB,0
MOVLW 0x0F
ANDWF PORTB,F
MOVF R4L,W
ANDLW 0xF0
IORWF PORTB,F
CALL LCX1
SWAPF R4L,F
MOVLW 0x0F
ANDWF PORTB,F
MOVF R4L,W
ANDLW 0xF0
IORWF PORTB,F
CALL LCX1
MOVLW 0x64
MOVWF R4L
CALL X001
RETURN
LCX1: BSF PORTB,1
NOP
NOP
BCF PORTB,1
NOP
NOP
RETURN
; Lcdcmdout Routine
LC02: MOVWF R4L
BCF PORTB,0
MOVLW 0x0F
ANDWF PORTB,F
MOVF R4L,W
ANDLW 0xF0
IORWF PORTB,F
CALL LCX1
SWAPF R4L,F
MOVLW 0x0F
ANDWF PORTB,F
MOVF R4L,W
ANDLW 0xF0
IORWF PORTB,F
CALL LCX1
MOVLW 0x88
MOVWF R4L
MOVLW 0x13
MOVWF R4H
CALL Y001
RETURN
; Lcdout Decimal Conversion Routine
LC21:
MOVLW 0x2C
MOVWF FSR
LC22:
MOVF INDF,W
BTFSC STATUS,Z
RETURN
INCF FSR,F
CALL LC01
GOTO LC22
; APPEND CODE BEGIN: _routine_ascii_word_
_append_lab_0001:
MOVLW 0x2C
MOVWF FSR
BCF 0x34,0
MOVF 0x32,W
MOVWF R2L
MOVF 0x33,W
MOVWF R2H
MOVLW 0x10
MOVWF R1L
MOVLW 0x27
MOVWF R1H
CALL _append_lab_0002
MOVLW 0xE8
MOVWF R1L
MOVLW 0x03
MOVWF R1H
CALL _append_lab_0002
MOVLW 0x64
MOVWF R1L
CLRF R1H
CALL _append_lab_0002
MOVLW 0x0A
MOVWF R1L
CLRF R1H
CALL _append_lab_0002
MOVF R2L,W
CALL _append_lab_0003
CLRF 0x00
RETURN
_append_lab_0002:
MOVF R2L,W
MOVWF R0L
MOVF R2H,W
MOVWF R0H
CALL D001
MOVF R0L,W
BTFSC 0x03,2
GOTO L0004
BSF 0x34,0
L0004:
BTFSS 0x34,0
GOTO L0005
_append_lab_0003:
ADDLW 0x30
MOVWF 0x00
INCF FSR,f
L0005:
RETURN
; APPEND CODE END.
; End of listing
END
Any advice as to what's going on is appreciated!!
Last edited: