alexlopez2612
New Member
Hi,
I have a 40X2 3V and I was hopping that this new (and expensive) chip, could give more speed to my circuit.
I had de 40X2 with a 8MHz cristal and with setfreq em32 and now, when I have the 40X2 3V, 16MHz cristal, and a setfreq em64, I can see any difference...
I don't know if this too much to ask here, so, please, let me know where I can found a solution, because I'm looking and testing for a lot of places.
Do I need to do something else?
This is my code (if it helps to see anything wrong):
Thank you for you help
I have a 40X2 3V and I was hopping that this new (and expensive) chip, could give more speed to my circuit.
I had de 40X2 with a 8MHz cristal and with setfreq em32 and now, when I have the 40X2 3V, 16MHz cristal, and a setfreq em64, I can see any difference...
I don't know if this too much to ask here, so, please, let me know where I can found a solution, because I'm looking and testing for a lot of places.
Do I need to do something else?
This is my code (if it helps to see anything wrong):
Code:
let dirsB = %00000000 'seteamos portB como entradas
let dirsD = %11111111 'seteamos portD como salidas
symbol DIR_FISICA = b6
'variables para trama de transmisión/recepción
symbol DIR_TRAMA = b10
symbol FUNCION = b11
symbol DATA_BYTE_0 = b12
symbol DATA_BYTE_1 = b13
symbol DATA_WORD_0 = w7
symbol DATA_WORD_1 = w8
symbol DATA_WORD_2 = w9
symbol DATA_WORD_3 = w10
symbol DATA_WORD_4 = w11
symbol DATA_WORD_5 = w12
symbol DATA_WORD_6 = w13
symbol DATA_WORD_7 = w14
symbol OK_BYTE = b30
symbol CRC_BYTE = b31
'Var generales
setfreq em64 'comando que cuadriplica la freq del cristal de 8MHz a 32MHz
low c.2 'ponemos el 485 en modo escucha
gosub set_485_address
sertxd("la direccion es ",#DIR_FISICA,13,10)
hsersetup B57600_64,%00
main:
low c.2'si se ha cortado la comunicación, esperamos en modo escucha
'serin c.0,T38400_32,DIR_TRAMA,FUNCION,DATA_BYTE_0,CRC_BYTE
hserin [1000,main],0,4
ptr = 0 ; reset sp pointer
' get 0,DIR_TRAMA
get 1,FUNCION
get 2,DATA_BYTE_0
get 3,CRC_BYTE
if @ptr = DIR_FISICA then
high c.2 'habilitamos el 485 para transmitir
select case FUNCION 'evaluamos la funcion del
case 2 'Leer y enviar a PC entradas y salidas
gosub memory_read 'leo las entradas
let OK_BYTE = 255 'OK provisional
let CRC_BYTE = 0 'CRC provisional
gosub envio 'envío trama respuesta
case 3
let pinsD = DATA_BYTE_0 'seteo las salidas
gosub memory_read 'leo las entradas
let OK_BYTE = 255 'OK provisional
let CRC_BYTE = 0 'CRC provisional
gosub envio 'envio trama respuesta
endselect
endif
goto main
envio:
pause 10
hserout 0,(DIR_TRAMA,FUNCION,DATA_BYTE_0,DATA_BYTE_1,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,OK_BYTE,CRC_BYTE,10)
low c.2 'volvemos el 485 para escuchar
return
memory_read: 'subrutina que lee todas las DI, DO y AI
let DATA_BYTE_0 = pinsB 'leemos DI de puerto B y lo metemos al byte de la trama
let DATA_BYTE_1 = outpinsD 'leemos status de las DO y lo metemos al byte de la trama
readadc10 a.0,DATA_WORD_0 'metemos la AI0 en el word de la trama.
readadc10 a.1,DATA_WORD_1 'metemos la AI1en el word de la trama.
readadc10 a.2,DATA_WORD_2 'metemos la AI2 en el word de la trama.
readadc10 a.3,DATA_WORD_3 'metemos la AI3 en el word de la trama.
'readadc10 a.4,DATA_WORD_4 'metemos la AI4 en el word de la trama. REASIGNAR A OTRO PIN; ESTE NO ES ADC
readadc10 a.5,DATA_WORD_5 'metemos la AI5 en el word de la trama.
readadc10 a.6,DATA_WORD_6 'metemos la AI6 en el word de la trama.
readadc10 a.7,DATA_WORD_7 'metemos la AI7 en el word de la trama.
return
set_485_address:
let DIR_FISICA = 0
if pinC.0 = 1 then
setbit DIR_FISICA,0
endif
if pinC.1 = 1 then
setbit DIR_FISICA,1
endif
if pinC.5 = 1 then
setbit DIR_FISICA,2
endif
if pinC.4 = 1 then
setbit DIR_FISICA,3
endif
return