that last line was wrong should be
day = ((reg_val[3] >> 4) * 10) + (reg_val[3]$0f) ; bcd2bin conversion
lcdout dec2 day
must have been too early in the morning for me
that last line was wrong should be
day = ((reg_val[3] >> 4) * 10) + (reg_val[3]$0f) ; bcd2bin conversion
lcdout dec2 day
must have been too early in the morning for me
It took me a moment... I'm blaming it on mashed potato poisoning - self inflicted, don't call the police.
In fact, I use a similar function to convert the calendar registers to decimal (and back) as part of each read and write routine. The problem comes in trying to use that decimal value to retrieve text characters. The math:
REG_VAL[5] = 1 in January... So:
READ 097 + (REG_VAL[5] * 3) + 0 = DATA position 100; CA_MONTH[0] = "J"
READ 097 + (REG_VAL[5] * 3) + 1 = DATA position 101; CA_MONTH[1] = "A"
READ 097 + (REG_VAL[5] * 3) + 2 = DATA position 102; CA_MONTH[2] = "N"
The problem... On the LCD the first character in munged - displays as "$AN", where $ represents some random pattern of dots. When REG_VAL[5] = 2, I get $EB; 3 = $AR... Indicating that the month is correctly decoded and the DATA located properly. As they say, "Everything is perfect, it just don't work".
The day (MO, TU, WE...) is decoded similarly from REG_VAL[3] (starting at DATA location 137) and displays as it should.
looks like I got hold of the wrong end of the stick again
tried this
resultCode:'**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 29/11/2014 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** #CONFIG cfg1 = _FOSC_INTOSC cfg1&= _WDTE_ON cfg1&= _PWRTE_OFF cfg1&= _MCLRE_ON cfg1&= _CP_OFF cfg1&= _CPD_OFF cfg1&= _BOREN_ON cfg1&= _CLKOUTEN_OFF cfg1&= _IESO_ON cfg1&= _FCMEN_ON __CONFIG _CONFIG1, cfg1 cfg2 = _WRT_OFF cfg2&= _PLLEN_OFF cfg2&= _STVREN_ON cfg2&= _BORV_19 cfg2&= _LVP_OFF __CONFIG _CONFIG2, cfg2 #ENDCONFIG DATA @ 100, "J", "A", "N", "F", "E", "B", "M", "A", "R", "A", "P", "R", "M", "A", "Y", "J", "U", "N", "J", "L", "Y", "A", "U", "G", "S", "E", "P", "O", "C", "T", "N", "O", "V", "D", "E", "C" ;DATA @ 137, "S", "U", "M", "O", "T", "U", "W", "E", "T", "H", "F", "R", "S", "A", "S", "U" CA_MONTH var byte[3 ] reg_val var byte osccon=$6a '4 mhz anselA=0 main: for reg_val =1 to 12 gosub expand_date Serout2 PORTA.0,84,["m",#reg_val ," ",str ca_month \3 ,13,10] next goto main EXPAND_DATE: READ 097 + (reg_val * 3) + 0, CA_MONTH[0] READ 097 + (reg_val * 3) + 1, CA_MONTH[1] READ 097 + (reg_val * 3) + 2, CA_MONTH[2] RETURN
Code:m1 JAN m2 FEB m3 MAR m4 APR m5 MAY m6 JUN m7 JLY m8 AUG m9 SEP m10 OCT m11 NOV m12 DEC
so the method is sound . reg_val[5] is binary not BCD right ?
otherwise post entire code , I suspect an array overrun is most likely problem
ps another method using flash mem not eprom :- for more ideas
lookup pkt[3],["xmtwtfss"], day[0]
lookup pkt[3],["xouehrau"], day[1]
lookup pkt[3],["xnenuitn"], day[2]
Last edited by richard; - 28th November 2014 at 23:10.
Bookmarks