estoy intentando cargar dos valores en una variable de tipo word, uno de ellos en el byte alto y otro en el bajo,
cuando imprimo el resultado por el terminal solo veo lo que he cargado en el byte bajo.
sub muestra_cad(cad_num as string)
dim cont as byte
dim char as Byte
dim value as word
HSerPrint ">>>cadena que entra ":HSerPrint cad_num
HSerPrintCRLF
char=0
set cs off
wait 10 us
for cont=1 to 8
char= val(mid(cad_num,cont,1))
char= (char and 0b00001111)
char= swap4(char) 'convertir a bcd
value_H = cont
value = char
hserprint "valor ":hserprint str(value_H):HSerPrintCRLF
gosub escribe_dato(value)
next
set cs on
wait 10 us
end sub
que estoy haciendo mal ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
El programa debe presentar un dato con dos partes . El byte superior contiene la direccion del registro que va a contener el byte inferior de esta forma : xxxxDDDD.NNNNxxxx .
El problema es que cuando escribo el contador del bucle (1..8)(DDDD) en el byte superior el oscilograma solo muestra los cambios en el byte inferior (NNNN).
el programa provisional esta aquí y lo compruebo con un analizador lógico.
'**********
'enviar datos al display MAX7219 EN MODO 7 SEGMENTOS
'**********
'######################################################################
'DEFINIR PINES DE ENTRADA/SALIDA
'######################################################################
define SCK PortC.4 'clk out
define dato PortC.2 'out
define cs PortC.3 'cs
'----------------------------------------------------------------------
dir PORTC.4 out
dir PORTC.3 out
dir PORTC.2 out
'######################################################################
'DEFINIR VARIABLES
'######################################################################
dim bit_estado as BIT
dim dato_display as word
dim dir_data as byte 'direccion donde pondremos el dato
dim valor_calc as Long 'valor en coma flotante calculado
dim val_cad as string *10 'valor en coma flotante transformado
dim ctfor as byte 'en cadena
dim nibble_dato as byte 'dato para el display
dim nibble_dir as byte 'dato para la direccion
wait 2 s
set sck off
valor_calc = 10101011
val_cad= str32(valor_calc)
'####################################################################
'ENVIA UN VALOR NUMERICO EN FORMATO STRING
'examinamos la cadena para ver si hay punto decimal añaadimos el bit7
'en caso contrario mandamos el bite en formato BCD a su posicion
'####################################################################
sub muestra_cad(cad_num as string)
dim cont as byte
dim char as Byte
dim value as word
HSerPrint ">>>cadena que entra ":HSerPrint cad_num
HSerPrintCRLF
char=0
set cs off
wait 10 us
for cont=1 to 8
char= val(mid(cad_num,cont,1))
char= (char and 0b00001111)
char= swap4(char) 'convertir a bcd
value_H = cont
value = char
hserprint "valor ":hserprint str(value_H):HSerPrintCRLF
gosub escribe_dato(value)
next
set cs on
wait 10 us
end sub
'#####################################################################
'pendiente de revisar
'#####################################################################
sub com_lev
'######################################################################
'modo BCD O 7 SEGMENTOS
'######################################################################
sub com_mode_BCD
dato_display_H =0x09 'direccion
dato_display =0x0f 'dato modo bcd
gosub escribe_dato(dato_display)
end sub
'######################################################################
'NUCLEO PRINCIPAL
'SUBRUTINA BASICA DE ENVIO SINCRONIZADO DE UNA WORD al dispositivo max7219
'######################################################################
sub escribe_dato(dato7seg as word)
dim cntA as Byte
SETdatooffwait5ussetcsoff'iniciamos el envio de bits wait 5 us for cntA=16 to 1 step -1 set sck off wait 15 ussetwith(dato,(dato7seg.cntA))'saca el dato por la linea seleccionada wait 15 us set sck on wait 15 us set dato off wait 5 us next set cs on SET sck off wait 10 usSETdatooff'finaliza el envio de datos
end sub
el cambio de tamaño de texto lo genera este publicador en origen no es así.
'######################################################################
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is a common oversight when using WORDS and BYTES.
You have assigned a value to the _H part of a WORD variables, then assigned a BYTE to the WORD which overwrites the _H
Simply change as follows:
value = char
value_H = cont
Now the WORD variable is assigned with the value of char and then the _H part of a WORD is assigned the value of cont
Easy oversight to make.
Code improvement for you
for cont=1 to cad_num(0)
char= cad_num(cont)
char= (char and 0b00001111)
char= swap4(char) 'convertir a bcd
value = char
value_H = cont
hserprint "valor ":hserprint str(value_H):hserprint str(value):HSerPrintCRLF
next
Last edit: Anobium 2022-02-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
En primer lugar quiero agradecer su interés por resolver mi problema. No le parece a usted que es suficiente indicar la extension _H _E _U sobre la variable para limitar el rango de asignación ? .
Si yo asigno un "byte " a una "word_h" ,lo estoy asignando a una parte de esa variable y no a toda la variable porque uso 1 byte y no otra variable de tipo word . Es un problema si pretendo modificar una variable mas grande de manera parcial . No le parece a usted que esto sea así?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all I want to thank you for your interest in solving my problem.
Pleasure
It does not seem to you that it is sufficient to indicate the extension _H _E _U over the variable to limit the allocation range ? . If I assign a "byte" to a "word_h", I am assigning it to a part of that variable and not to the whole variable because I use 1 byte and not another variable of type word. It is a problem if I intend to modify a larger variable partially. Don't you think this is so?
This is not the case of indication of the extension. It is simply the order of assigning variables.
If you use [cast] then it would have worked. As follows:
estoy intentando cargar dos valores en una variable de tipo word, uno de ellos en el byte alto y otro en el bajo,
cuando imprimo el resultado por el terminal solo veo lo que he cargado en el byte bajo.
sub muestra_cad(cad_num as string)
dim cont as byte
dim char as Byte
dim value as word
HSerPrint ">>>cadena que entra ":HSerPrint cad_num
HSerPrintCRLF
char=0
set cs off
wait 10 us
for cont=1 to 8
char= val(mid(cad_num,cont,1))
next
set cs on
wait 10 us
end sub
que estoy haciendo mal ?
Can you post the rest of the program? This will not compile.
And, we cannot tell (or guess) the range of the parameter muestra_cad.
Last edit: Anobium 2022-02-12
Is this as simple as you are not showing the correct byte of the word?
hserprint "valor ":hserprint str(value_H):hserprint str(value):HSerPrintCRLF
El programa debe presentar un dato con dos partes . El byte superior contiene la direccion del registro que va a contener el byte inferior de esta forma : xxxxDDDD.NNNNxxxx .
El problema es que cuando escribo el contador del bucle (1..8)(DDDD) en el byte superior el oscilograma solo muestra los cambios en el byte inferior (NNNN).
el programa provisional esta aquí y lo compruebo con un analizador lógico.
'**********
'enviar datos al display MAX7219 EN MODO 7 SEGMENTOS
'**********
chip mega328p,16
#option Explicit
#define USART_BAUD_RATE 9600
#define USART_BLOCKING
#define USART_DELAY OFF
'######################################################################
'definir CONSTANTES
'######################################################################
define 8digit 0x07
define 4digit 0x03
define decBCD 0x0f
define luxLevel_l 0x03
define luxLevel_m 0x0A
define luxLevel_h 0x0f
'######################################################################
'DEFINIR PINES DE ENTRADA/SALIDA
'######################################################################
define SCK PortC.4 'clk out
define dato PortC.2 'out
define cs PortC.3 'cs
'----------------------------------------------------------------------
dir PORTC.4 out
dir PORTC.3 out
dir PORTC.2 out
'######################################################################
'DEFINIR VARIABLES
'######################################################################
dim bit_estado as BIT
dim dato_display as word
dim dir_data as byte 'direccion donde pondremos el dato
dim valor_calc as Long 'valor en coma flotante calculado
dim val_cad as string *10 'valor en coma flotante transformado
dim ctfor as byte 'en cadena
dim nibble_dato as byte 'dato para el display
dim nibble_dir as byte 'dato para la direccion
wait 2 s
set sck off
valor_calc = 10101011
val_cad= str32(valor_calc)
'######################################################################
' -------------PROGRAMA PRINCIPAL--------------
'######################################################################
gosub com_mode_BCD
gosub com_7lim
gosub com_lev
do
loop
'####################################################################
'ENVIA UN VALOR NUMERICO EN FORMATO STRING
'examinamos la cadena para ver si hay punto decimal añaadimos el bit7
'en caso contrario mandamos el bite en formato BCD a su posicion
'####################################################################
sub muestra_cad(cad_num as string)
dim cont as byte
dim char as Byte
dim value as word
HSerPrint ">>>cadena que entra ":HSerPrint cad_num
HSerPrintCRLF
char=0
set cs off
wait 10 us
for cont=1 to 8
char= val(mid(cad_num,cont,1))
next
set cs on
wait 10 us
end sub
'#####################################################################
'pendiente de revisar
'#####################################################################
sub com_lev
dato_display_H =0x0A 'direccion
dato_display =luxLevel_h 'dato luxLevel_H, luxLevel_L
gosub escribe_dato(dato_display)
end sub
'#####################################################################
'cuantos digitos
'#####################################################################
sub com_7lim
dato_display_H =0x0B 'direccion
dato_display =0x07 'dato 7 digitos
gosub escribe_dato(dato_display)
end sub
'######################################################################
'modo BCD O 7 SEGMENTOS
'######################################################################
sub com_mode_BCD
dato_display_H =0x09 'direccion
dato_display =0x0f 'dato modo bcd
gosub escribe_dato(dato_display)
end sub
'######################################################################
'NUCLEO PRINCIPAL
'SUBRUTINA BASICA DE ENVIO SINCRONIZADO DE UNA WORD al dispositivo max7219
'######################################################################
sub escribe_dato(dato7seg as word)
dim cntA as Byte
end sub
el cambio de tamaño de texto lo genera este publicador en origen no es así.
'######################################################################
So, I can understand. Please confirm the attached file shows the issue.
I see the issue!
This is a common oversight when using WORDS and BYTES.
You have assigned a value to the
_H
part of a WORD variables, then assigned a BYTE to the WORD which overwrites the_H
Simply change as follows:
Now the WORD variable is assigned with the value of
char
and then the_H
part of a WORD is assigned the value ofcont
Easy oversight to make.
Code improvement for you
Last edit: Anobium 2022-02-12
En primer lugar quiero agradecer su interés por resolver mi problema.
No le parece a usted que es suficiente indicar la extension _H _E _U sobre la variable para limitar el rango de asignación ? .
Si yo asigno un "byte " a una "word_h" ,lo estoy asignando a una parte de esa variable y no a toda la variable porque uso 1 byte y no otra variable de tipo word . Es un problema si pretendo modificar una variable mas grande de manera parcial . No le parece a usted que esto sea así?
Pleasure
This is not the case of indication of the extension. It is simply the order of assigning variables.
If you use
[cast]
then it would have worked. As follows:[byte]value_h =[byte] char
NOT where value is NOT a byte variable.
value = char
[byte]value_h = char
lds SysValueCopy,CHAR
sts VALUE_H,SysValueCopy
NOT
;value = char
lds SysValueCopy,CHAR
sts VALUE,SysValueCopy
ldi SysValueCopy,0
sts VALUE_H,SysValueCopy
;
Last edit: Anobium 2022-02-12