Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
Beste heren,
Na een paar drukke laatste schoolweken en een paar weekjes uitrusten de hobby maar weer eens opgepakt.
Ik ben zoals sommige van jullie weten bezig met het maken van een spanning/stoom meter voor in mijn labvoeding.
Dit alles dmv een PIC16F88.
Alles leuk en aardig, eerdere problemen zijn opgelost, LC-Display werkt en ben begonnen met het aansturen/uitlezen van 2 AD-channels.
Nu heb ik na een dag zoeken, code schrijven en testen mijn fout nog niet gevonden.
De waar die de AD uit blijft geven is b'00000000'in ADRESH (left justified!)
in het kort even mijn code (alle overig zooi die nix met ad te maken hebben er uit "geknipt"):
INIT CLRF STATUS
CLRF PORTA
CLRF PORTB
MOVLW 0x03 ; set PORTB to <:>INPUT & <0:7>OUTPUT
BANKSEL TRISA
MOVWF TRISA
MOVLW 0x00 ; set PORTB to <:>INPUT & <0:7>OUTPUT
BANKSEL TRISB
MOVWF TRISB
BANKSEL ANSEL
MOVLW 0x03 ; set AN<2:6> Inputs to digital, AN<0:1> to analog
MOVWF ANSEL
BANKSEL OSCTUNE
BSF OSCTUNE,TUN5
BCF OSCTUNE,TUN4
BSF OSCTUNE,TUN3
BSF OSCTUNE,TUN2
BANKSEL ADCON1 ; select bank voor AD 0
CLRF ADCON1 ; clear het register
BSF ADCON1,2 ; set number of analog channels and ref to 3/0
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'01000001' ; Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
BANKSEL PORTA
CLRF PORTA
CLRF PORTB
CLRF ADRESH
BSF PORTB,LED_B
MAIN CALL AD_CH0
; hier staat een stuk om de waarde die uit ADRESH komt binair op het display te zetten.
CALL DELAY_5SEC ; wacht en flinke tijd voor er een nieuw conversie komt
GOTO MAIN
AD_CH0
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'01000001' ; Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
CALL SHORTDLY ; wacht een acquisition time van 50 usec
BSF ADCON0,GO ;Start A/D conversion
WAIT_CH0
BTFSC ADCON0,GO ;Wait for conversion to complete
GOTO WAIT_CH0
MOVF ADRESH,W
MOVWF TEMP_RESH
RETURN
Is er iemand die mij een handje verder kan helpen want ik zit helemaal vast.
alvast bedankt iedereen!
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
orgineel is de code met 2 AD's en om dat er van channel gewisselt word moet dit er dus 2(of 3 keer met de init mee) instaan. channal 1 is in deze code voor het overzicht ff weg gelaten
maar ik ga eens kijken wat dit opleverd 
[edit]
oke dit werkt nu, er word een conversie uitgevoerd, echter de conversie is niet stabiel. Er komen steeds verschillende waarde uit.
Ref = GND - 5V. op de ingang word 5V gezet dus zou je verwachten dat er een waarde van b'11111111' afgegeven zou moeten worden. echter de waarde die afgegeven wordt is veel lager.
iemand die weet hoe dit kan? en wat ik hier tegen kan doen?
[Bericht gewijzigd door Red-E op (46%)]
Fuzzbass
Mijn echte naam: Joris | Mijn elektronica website: Fuzzcraft.com
Weet je zeker dat je justificatie goed gaat en dat je de juiste bit pakt?
In ieder geval moet je zorgen voor een EXTREEM stabiele voeding, als je aan de voeding refereert. Gebruik bijvoorbeeld een RLC filter, en ontkoppel de PIC ook nog eens goed. Lukt dat niet, dan moet je een externe referentiediode aan de PIC hangen.
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
heb hier op mijn breadboard netjes mijn 7805 ontkoppeld etc etc... PIC ook ontkoppeld met 100nF... scoop er een bij gepakt...
een mooie strakke lijn op het scherm,geen pieken of iets dergelijks te zien, dus stabiel 
en wat bedoel je met justificatie Fuzzbass???
Arco
Special Member
Arco - "Simplicity is a prerequisite for reliability" - hard-, firm-, en software ontwikkeling: www.arcovox.com
BSF ADCON1,2 ; set number of analog channels and ref to 3/0??? - ADCON1:[3...0] bits zijn 'unimplemented'...
Justificatie is left/right justification of ADRESH:ADRESL
[Bericht gewijzigd door Arco op (19%)]
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
Op 16 juli 2009 19:42:41 schreef Red-E:
Beste heren,...De waar die de AD uit blijft geven is b'00000000'in ADRESH (left justified!)...
hak al gezegt geloof
heb er speciefiek opgelet dat het left justiefied is... ofwel de 6 lsb van ADRESL zijn '0'.
Lees daarom de waarde uit ADRESH
en bedankt voor de tip... zie het nu ook
heb het aangepast... conversies lijken nu iets beter te gaan maar compleet stabiel zijn ze nog niet... blijven wisselende waardes te voorschijn komen... 
Fuzzbass
Mijn echte naam: Joris | Mijn elektronica website: Fuzzcraft.com
Arco
Special Member
Arco - "Simplicity is a prerequisite for reliability" - hard-, firm-, en software ontwikkeling: www.arcovox.com
Als je Vcc als referentie gebruikt krijg je nooit een stabiele (nauwkeurige) uitlezing. Externe aparte VRef gebruiken...
Wat noem je trouwens wisselende waarden? Als je Vcc als referentie gebruikt kan dat makkelijk 20 stapjes schommelen (is maar 0.09v)
[Bericht gewijzigd door Arco op (36%)]
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
Heb net 10 sample's genomen om te kijken hoe hard het variert. het hoogste sample wast 0x58 => b'01011000' ne het laagst sample 0x08, dit scheelt volgens mijn meer dan 20 stapjes
en die 20 stapjes zouden niet zo veel uit maken ik wil een meting doen met slechts een tiende nauwkeurig. dus die 0.9V zal je waarschijnlijk niet zien.
Hoe moet ik dan gebruik maken van die externe referentie spanning? de voedingsspanning direct aan de Vref+ ingang hangen heeft nog geen zin volgens mij, zou het zelf zijn als de interne refertiespanning gebruiken. of zie ik dat verkeerd?
Op 16 juli 2009 20:49:13 schreef Fuzzbass:
... Lukt dat niet, dan moet je een externe referentiediode aan de PIC hangen.
wat word er door Fuzzbass bedoeld met die externe referentiediode? bijvoorbeeld een 1N4148 in gelijdings richting van de +5V naar de Vref+ ingang?
alvast bedankt.
Dat is wel een heel grote storing op je voeding dan, het lijkt me sterk. Er zal wat anders fout zitten.
Klopt je AD snelheid t.o.v. je clockfrequentie?
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
Hoe bedoel je dit zonnepanneeltje?
Heb er voor gekozen om mijn snelheid in testellen op: Fosc/8
ik maak gebruik van een externe oscillator van 20MHz, dus de AD loopt op 2.5MHz als ik mij niet vergis.
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
oke... inderdaad zit er een stuk naast, hij loopt op 5MHz volgens de datasheet (hoofstuk 12 tabel 12-1)
Operation ADCS<2> ADCS<1:0> Max.
8 TOSC 0 01 5 MHz
maar waar moet ik nu op letten zonnepaneeltje?
je vraagt: Klopt je AD snelheid t.o.v. je clockfrequentie?
maar wat bedoel je hiermee en hoe kan ik dit na gaan?
(dit is de eerste keer dak de AD van een PIC gebruik, geef me een ARM7 (LPC2148) en het werkt binnen een paar minuten ^^)
[Bericht gewijzigd door Red-E op (15%)]
Zelfs op een breadboard met gestabiliseerde 5V zal je uitlezing hoogstens een paar bits mogen varieeren.
De device frequentie is 20MHz, dan heb je 32 of 64 Tosc nodig.
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
oke... er zijn nu een aantal aanpassing gedaan aan mijn programma.
Het word steeds beter maar het is nogsteeds niet wat het moet zijn. de schommelingen blijven te groot.
code die ik nu heb:
INIT CLRF STATUS
CLRF PORTA
CLRF PORTB
MOVLW 0x03 ; set PORTB to <:>INPUT & <0:7>OUTPUT
BANKSEL TRISA
MOVWF TRISA
MOVLW 0x00 ; set PORTB to <:>INPUT & <0:7>OUTPUT
BANKSEL TRISB
MOVWF TRISB
BANKSEL ANSEL
MOVLW b'00000011' ; set AN<2:7> Inputs to digital, AN<0:1> to analog
MOVWF ANSEL
BANKSEL OSCTUNE
BSF OSCTUNE,TUN5
BCF OSCTUNE,TUN4
BSF OSCTUNE,TUN3
BSF OSCTUNE,TUN2
BANKSEL ADCON1 ; select bank voor AD 0
CLRF ADCON1 ; clear het register
;BSF ADCON1,ADCS2 ; instellen van de conversie clock op 64/Fosk
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'10000001' ; Fosc/32 [7-6], A/D ch0 [5-3], a/d on [0]
MOVWF ADCON0
BANKSEL PORTA
CLRF PORTA
CLRF PORTB
CLRF ADRESH
BSF PORTB,LED_B
; hier staat normaalgesproken LCD stuff
;een voudig programma voor het nemen van samples om de 2.5sec
MAIN CALL AD_CH0 ; neem een sample op channel 0
CALL DISPLAY_BCH0 ; zet deze binair op het LCD
CALL DELAY_2_5SEC ; wacht 2.5 sec tot volgende sample
GOTO MAIN
AD_CH0
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'10000001' ; Fosc/32 [7-6], A/D ch0 [5-3], a/d on [0]
MOVWF ADCON0
CALL DELAY_20US
BSF ADCON0,GO ;Start A/D conversion
WAIT_CH0
BTFSC ADCON0,GO ;Wait for conversion to complete
GOTO WAIT_CH0
MOVF ADRESH,W
MOVWF TEMP_RESH
RETURN
Iemand die nog dingen ziet?
Is er iemand die het werkend heeft op een 16F88??
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
en nog iets meer
thx... nu klopt het wel
staat er wel in de code maar niet gecopyd...
[Bericht gewijzigd door Red-E op (33%)]
Op 17 juli 2009 15:46:43 schreef Red-E:
Is er iemand die het werkend heeft op een 16F88??
In Picbasic was dat zo klaar (op een bitje na).
; ADCON0 definitions
Declare ADIN_RES 10 ' 10-bit result required
Declare ADIN_TAD 32_FRC ' OSC/32 chosen
Declare ADIN_STIME 50 ' Allow 50us sample time
PORTA = %00000000 ' all porta's low
TRISA = %00001111 ' AN0+AN1+AN2+AN3 as an input
ADCON1 = %10100000 ' right justified, Vref=AN3 & 0V=Vss
ANSEL = %00001111 ' AN0+AN1+AN2 adc inputs, Vref=AN3
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
Fuzzbass
Mijn echte naam: Joris | Mijn elektronica website: Fuzzcraft.com
Mijn laatste project met een F88 draait op 4,0 volt (vraag niet waarom). De PIC heeft samen met nog een 74HC00 een eigen spanningsregelaar, geheel los van de rest van de PCB. De spanning meten doe ik zonder dat de 3,6 MHz kristaloscillator draait, dus op de interne RC oscillator. Die zorgt voor veel minder ruis. De te meten spanning heb ik gebufferd met een 1 μF tantaaltje. De PCB is boven en onder voorzien van ground plane, en zelfs dan heb ik nog de ground paden zo kort mogelijk gehouden.
De toepassing heeft genoeg aan 8 bit, maar het presteert ver boven verwachting. De spanning schommelt hooguit 1 LSB op 10 bit.
Op 17 juli 2009 19:11:16 schreef Red-E:
wat heb jij gebruikt als Vref? gewoon je voeding +5v??
TL431, 2.5V ref.
Arco
Special Member
Arco - "Simplicity is a prerequisite for reliability" - hard-, firm-, en software ontwikkeling: www.arcovox.com
Als je een complete werkende code post, kunnen we het misschien testen. Zo valt er weinig van te zeggen...
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
zal morgen even een copie maken van mijn compleete code en even kijken of ik een schematje heb
(voor zoveer nodig ivm het display
)
Red-E
Gr. Red-E || There are only 10 types of people in the world. Those who understand binary, and those who don't ||
Heren,
zoals belooft voor ik nu naar bed ga... (heb nacht dienst gehad
) even een copy van mijn totale code.
;******************************************************************************
; *
; Filename: Meter_16F88_V0_2.asm *
; Date: 31/05/2009 *
; File Version: V0.2 *
; *
; Author: E.J.G Bergkamp *
; Company: Electronic Porductions *
; *
;******************************************************************************
; *
; Features of the 16F88: *
; *
; 1 10-bit PWM *
; 8 MHz Internal Oscillator *
; ICD support *
; 256 bytes of EEPROM data memory *
; Capture/Compare Module *
; *
;******************************************************************************
; *
; Notes: *
; *
; *
;******************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST p=16F88 ; list directive to define processor
#INCLUDE <P16F88.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _CPD_OFF & _CP_OFF & _DEBUG_OFF & _LVP_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF &
_WRT_PROTECT_OFF & _HS_OSC & _BODEN_OFF
errorlevel 0,-302,-305 ; turn off the "Register in operand nog in bank 0. Ensure that bank bits are correct" message
; ***** DEFINES *****
#DEFINE LED_B 7
; ***** EQUATES *****
; ***** LCD stuff *****
LCDEnable EQU 5
LCDRS EQU 4
LCDByte EQU 0x23
LCDAdd EQU 0x24
hiByte EQU 0x25
loByte EQU 0x26
nibToSend EQU 0x27
A_SHADOW EQU 0x50 ; shadow registers for port A and B
B_SHADOW EQU 0x51
d1 EQU 0x52 ; register for the delay
d2 EQU 0x53 ; register for the delay
d3 EQU 0x54 ; register for the delay
W_TEMP EQU 0x7D ; w register for context saving (ACCESS)
STATUS_TEMP EQU 0x7E ; status used for context saving (ACCESS)
PCLATH_TEMP EQU 0x7F ; variable used for context saving
; ***** AD stuff *****
TEMP_RESH EQU 0x30
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET ORG 0x00 ; processor reset vector
GOTO INIT ; go to beginning of program
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ISR ORG 0x04 ; interrupt vector location
; Context saving for ISR
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into W register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; END OF USER ISR
;------------------------------------------------------------------------------
; Restore context before returning from interrupt
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
INIT CLRF STATUS
CLRF PORTA
CLRF PORTB
MOVLW 0x03 ; set PORTB to <:>INPUT & <0:7>OUTPUT
BANKSEL TRISA
MOVWF TRISA
MOVLW 0x00 ; set PORTB to <:>INPUT & <0:7>OUTPUT
BANKSEL TRISB
MOVWF TRISB
BANKSEL ANSEL
MOVLW b'00000011' ; set AN<2:7> Inputs to digital, AN<0:1> to analog
MOVWF ANSEL
BANKSEL OSCTUNE
BSF OSCTUNE,TUN5
BCF OSCTUNE,TUN4
BSF OSCTUNE,TUN3
BSF OSCTUNE,TUN2
BANKSEL ADCON1 ; select bank voor AD 0
CLRF ADCON1 ; clear het register
;BSF ADCON1,ADCS2 ; instellen van de conversie clock op 64/Fosk
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'10000001' ; Fosc/32 [7-6], A/D ch0 [5-3], a/d on [0]
MOVWF ADCON0
BANKSEL PORTA
CLRF PORTA
CLRF PORTB
CLRF ADRESH
BSF PORTB,LED_B
LCD_INIT
CALL LONGDLY
CALL LCDFUN ; Set de LCD mode op 4 bit,2 regels ,5x7 font
CALL LONGDLY
CALL LCDDISP ; aanzetten van het display en cursor
CALL LONGDLY
CALL LCDENT ; sets auto increment right after write (like a typewriter)
CALL LCDCLR
CALL LCD_START_UP
CALL LCDCLR
; CALL LCDMAIN ; zet een malig op regen 1 respectivelijk regel 2 de teksten "Voltage:" & "Current:"
MAIN CALL AD_CH0
CALL DISPLAY_BCH0
CALL DELAY_2_5SEC
GOTO MAIN
AD_CH0
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'10000001' ; Fosc/32 [7-6], A/D ch0 [5-3], a/d on [0]
MOVWF ADCON0
CALL DELAY_20US
BSF ADCON0,GO ;Start A/D conversion
WAIT_CH0
BTFSC ADCON0,GO ;Wait for conversion to complete
GOTO WAIT_CH0
MOVF ADRESH,W
MOVWF TEMP_RESH
RETURN
AD_CH1
BANKSEL ADCON0 ; select bank voor AD config 0
MOVLW B'10000001' ; Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
MOVWF ADCON0
CALL DELAY_20US
BSF ADCON0,GO ;Start A/D conversion
WAIT_CH1
BTFSC ADCON0,GO ;Wait for conversion to complete
GOTO WAIT_CH1
MOVF ADRESH,W
MOVWF TEMP_RESH
RETURN
; ***** LCD_START_UP *****
; tekst die te zien is bij het opstarten van het systeem
; ************************
LCD_START_UP
movlw 2 ; on row 1, pos. 3 wright:
movwf LCDAdd ; "V&A-Meter"
CALL LCDADD
MOVLW "V"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "&"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "A"
MOVWF LCDByte
CALL LCDCHAR
MOVLW " "
MOVWF LCDByte
CALL LCDCHAR
MOVLW "-"
MOVWF LCDByte
CALL LCDCHAR
MOVLW " "
MOVWF LCDByte
CALL LCDCHAR
MOVLW "M"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "e"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "t"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "e"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "r"
MOVWF LCDByte
CALL LCDCHAR
movlw 44 ; on row 2, pos. 4 wright:
movwf LCDAdd ; "By Red-E"
CALL LCDADD
MOVLW "B"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "y"
MOVWF LCDByte
CALL LCDCHAR
MOVLW " "
MOVWF LCDByte
CALL LCDCHAR
MOVLW "R"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "e"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "d"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "-"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "E"
MOVWF LCDByte
CALL LCDCHAR
CALL DELAY_2_5SEC
RETURN
; ***** LCD_START_UP *****
; tekst die te zien is voor de meter, deze word NOOIT gewijzigd!
; ************************
LCDMAIN MOVLW 0 ; on row 1, pos. 0 wright:
MOVWF LCDAdd ; "Voltage:"
CALL LCDADD
MOVLW "V"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "o"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "l"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "t"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "a"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "g"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "e"
MOVWF LCDByte
CALL LCDCHAR
MOVLW 0xB ; on row 1, pos. 11 wright:
MOVWF LCDAdd ; "00.0V"
CALL LCDADD
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "."
MOVWF LCDByte
CALL LCDCHAR
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "V"
MOVWF LCDByte
CALL LCDCHAR
MOVLW 40 ; on row 2, pos. 0 wright:
MOVWF LCDAdd ; "Current:"
CALL LCDADD
MOVLW "C"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "u"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "r"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "r"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "e"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "n"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "t"
MOVWF LCDByte
CALL LCDCHAR
MOVLW 4B ; on row 2, pos. 11 wright:
MOVWF LCDAdd ; "0.00A"
CALL LCDADD
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "."
MOVWF LCDByte
CALL LCDCHAR
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "A"
MOVWF LCDByte
CALL LCDCHAR
RETURN
DISPLAY_BCH0
MOVLW 0 ; put ADRESH on LCD for debugging
MOVWF LCDAdd
CALL LCDADD
MOVLW "C"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "H"
MOVWF LCDByte
CALL LCDCHAR
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
MOVLW ":"
MOVWF LCDByte
CALL LCDCHAR
MOVLW " "
MOVWF LCDByte
CALL LCDCHAR
BTFSC ADRESH,7
MOVLW "1"
BTFSS ADRESH,7
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC ADRESH,6
MOVLW "1"
BTFSS ADRESH,6
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC TEMP_RESH,5
MOVLW "1"
BTFSS TEMP_RESH,5
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC TEMP_RESH,4
MOVLW "1"
BTFSS TEMP_RESH,4
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC TEMP_RESH,3
MOVLW "1"
BTFSS TEMP_RESH,3
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC TEMP_RESH,2
MOVLW "1"
BTFSS TEMP_RESH,2
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC TEMP_RESH,1
MOVLW "1"
BTFSS TEMP_RESH,1
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
BTFSC TEMP_RESH,0
MOVLW "1"
BTFSS TEMP_RESH,0
MOVLW "0"
MOVWF LCDByte
CALL LCDCHAR
RETURN
; ********** LCD-STUF ********** !! NOG FF COMENTAAR ORDENEN !!
LCDADD ; makes LCDAdd the current LCD Address
nop
BCF PORTB,LCDRS
movf LCDAdd, W
movwf LCDByte
bsf LCDByte, 7
CALL LCDBYTE
bsf PORTB,LCDRS
nop
nop
RETURN
LCDENT ; Entry Mode set - currently set to move cursor to right after each write
nop
BCF PORTB, LCDRS
movlw b'00000110'
movwf LCDByte
CALL LCDBYTE
BSF PORTB,LCDRS
nop
nop
RETURN
LCDDISP ; turns on display and cursor
nop
BCF PORTB,LCDRS
movlw b'00001100'
movwf LCDByte
CALL LCDBYTE
BSF PORTB,LCDRS
nop
nop
RETURN
LCDFUN ; sets up the LCD function byte, for 4 bit control, 2 lines, standard font
nop
movlw d'2'
movwf nibToSend
BCF PORTB, LCDRS ; we're sending a command, so R/S must be lo
CALL SENDNIB ; due to 4 bit operation, we have to resend the first nibble
CALL SHORTDLY
movlw b'00101000'
movwf LCDByte
CALL LCDBYTE
BSF PORTB, LCDRS
nop
nop
RETURN
LCDCLR ; clears the entire display
clrf LCDAdd
nop
movlw d'1'
movwf LCDByte
BCF PORTB, LCDRS ; 'cause we are doing a command, set the R/S line lo
CALL LCDBYTE ; writes LCDByte to the LCD
CALL LONGDLY ; Clearing the LCD takes ages, so a larger delay is needed
bsf PORTB, LCDRS ; set the R/S line, ready for characters
RETURN
LCDCHAR
;use this for displaying characters only, NOT control chars
;keeps track of cursor colation, and word wraps if necessary
movf LCDAdd, W
sublw h'50'
btfsc STATUS, Z
RETURN
CALL LCDBYTE
incf LCDAdd, F
; check if we have hit the end of the top line
movlw d'16'
subwf LCDAdd, W
btfsc STATUS, Z ; skip if not zero
GOTO LCDLINE2 ; must go to new line
RETURN
LCDLINE2 ; here we must go to the new line
movlw b'01000000'
movwf LCDAdd
CALL LCDADD
RETURN
LCDBYTE; sends a byte to the LCD, in 4bit fashion
; responsible for breaking up the byte to send into high and low nibbles
; and dumps them to LCD
;NOT responsible for the status of the LCDRS line, nor the major delays
; IN: LCDByte - distructive OUT: hiByte, loByte
clrf hiByte ; clears the vars, to prevent bugs
clrf loByte
bcf STATUS,W ; get rif of any carry which could screw up the bitshifts
rlf LCDByte, F
rlf hiByte
rlf LCDByte, F
rlf hiByte
rlf LCDByte, F
rlf hiByte
rlf LCDByte, F
rlf hiByte
movf LCDByte, W
movwf loByte
swapf loByte, F
movf hiByte,W
movwf nibToSend
CALL SENDNIB
movf loByte,W
movwf nibToSend
CALL SENDNIB
CALL SHORTDLY ; blocks until most instructions are done
RETURN
SENDNIB; responsible for sending nibble commands to the LCD.
;IN: nibToSend - non-distructive
clrw ; clears W
MOVLW 0xF0
ANDWF PORTB,W
MOVWF B_SHADOW
MOVF nibToSend,W
IORWF B_SHADOW,W
movwf PORTB ; => orgineel PORTA
nop
bsf PORTB, LCDEnable ; pulse the LCD Enable high
nop
nop
bcf PORTB, LCDEnable ; lower LCD Enable
nop
nop
RETURN
LCDBACKSPACE ; acts like a backspace
movf LCDAdd,W
andlw b'11111111'
btfsc STATUS, Z ; skip if not zero
RETURN ; already at end, so ignore backspace
sublw h'40'
btfsc STATUS, Z ; skip if at start of 2nd line
GOTO LCDBSTARTBOTLINE ; correct for moveing up to new line
decf LCDAdd,F;
CALL LCDADD ; move back one
movlw d'32' ; wipe the current char
movwf LCDByte
CALL LCDBYTE
CALL LCDADD
RETURN
LCDBSTARTBOTLINE ; correct for moveing up to new line
movlw d'15'
movwf LCDAdd
CALL LCDADD ; put us at 15
movlw d'32'
movwf LCDByte
CALL LCDBYTE
RETURN
; ***** Delay 20 us *****
DELAY_20US
;100 cycles
movlw 0x20
movwf d1
DELAY_20US_0
decfsz d1, f
goto DELAY_20US_0
RETURN
; ***** Delay 50 us *****
SHORTDLY
movlw 0x53
movwf d1
SHORTDLY_0
decfsz d1, f
goto SHORTDLY_0
return
; ***** Delay 25 ms *****
LONGDLY
movlw 0xA7
movwf d1
movlw 0x62
movwf d2
LONGDLY_0
decfsz d1, f
goto $+2
decfsz d2, f
goto LONGDLY_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
; ***** Delay 100ms *****
DELAY_100MS
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
DELAY_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY_0
;6 cycles
goto $+1
goto $+1
goto $+1
RETURN
; ***** Delay 2.5 sec *****
DELAY_2_5SEC
movlw 0x03
movwf d1
movlw 0x7F
movwf d2
movlw 0x1C
movwf d3
DELAY_2_5SEC_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY_2_5SEC_0
;6 cycles
goto $+1
goto $+1
goto $+1
return
end
hoop dat een van jullie de fout kan vinden met testen... als ik strax weer op ben ga ik zelf ook weer verder met prutsen en puzzelen 
alvast heel erg bedankt!