Hi Vasile,
This issue is that the serial_hw_read is non blocking, so depending on
the timing the incomming characters are randomly placed in dig1..dig4,
analyzing your code, the following might work:
var byte dig4[4] = {0,0,0,0}
var dig4_counter = 0
forever loop
var byte ch
while serial_hw_read ( ch ) loop
dig4[ dig4_counter & 0x03 ] = ch
dig4_counter = dig4_counter + 1
end loop
...
other code, using dig[ 0..3 ] i.s.o dig1..dig4
end loop
Albert
On 6 sep, 16:42, vasile surducan <[email protected]> wrote:
> Hi guys,
>
> I'm not give up easily, but still not being able to receive correct a four
> ASCII string.
> I'm receiving only the last char. Maybe I'm not using properly the library?
>
> Here is the code for two digits displayed on a 7seg :
>
> include 16f876
>
> pragma target clock 14_745_600
> pragma target osc hs
> pragma target wdt disabled
> pragma target pwrte enabled
> pragma target wrt no_protection
> pragma target lvp disabled
>
> include delay
> include seven_segment
>
> -- set all IO as digital
>
> ; enable_digital_io()
> adc_off
> var volatile bit _485_sense is pin_C5
> pin_c5_direction = output
> const bit RX_485 = low
> const bit TX_485 = high
>
> var volatile bit DIG1_R is pin_C1
> pin_C1_direction = output
> var volatile bit DIG2_R is pin_C2
> pin_C2_direction = output
> var volatile bit DIG3_R is pin_C3
> pin_C3_direction = output
> var volatile bit DIG4_R is pin_C4
> pin_C4_direction = output
> var volatile bit DP_R is pin_B7
> pin_B7_direction = output
>
> var volatile bit DIG1_V is pin_A1
> pin_A1_direction = output
> var volatile bit DIG2_V is pin_A2
> pin_A2_direction = output
> var volatile bit DIG3_V is pin_A4
> pin_A4_direction = output
> var volatile bit DIG4_V is pin_A5
> pin_A5_direction = output
> var volatile bit DP_V is pin_C0
> pin_C0_direction = output
> pin_C7_direction = input ; RX
> pin_C6_direction = output ; TX
>
> portB_direction = output
> portB = 0
> portB_direction = output
> portB = 0
> DP_R = LOW
> DP_V = LOW
>
> var byte data = 0
> var byte my_counter = 0
> var byte digit1, digit2, digit3, digit4 = 0
> var byte digit5, digit6, digit7, digit8 = 0
> var byte dig1, dig2, dig3, dig4
> var byte dig5, dig6, dig7, dig8
>
> procedure digit_display ( bit in d1_r, bit in d2_r, bit in d3_r, bit in
> d4_r,
> bit in d1_v, bit in d2_v, bit in d3_v, bit in
> d4_v) is
>
> DIG1_R = d1_r
> DIG2_R = d2_r
> DIG3_R = d3_r
> DIG4_R = d4_r
> DIG1_V = d1_v
> DIG2_V = d2_v
> DIG3_V = d3_v
> DIG4_V = d4_v
>
> end procedure
>
> ; const SERIAL_XMTBUFSIZE = 32 -- size of transmit buffer
> ; const SERIAL_RCVBUFSIZE = 64 -- size of receive buffer
> ; const SERIAL_DELTA = 17 -- spare space receive buffer
>
> const serial_hw_baudrate = 19200
>
> var bit dummyCTS_bit
>
> var bit serial_ctsinv is dummyCTS_bit -- incoming data flow
> control
>
> ; var bit serial_overflow_discard = true -- With transmit buffer overflow
> var bit serial_overflow_discard = false
>
> include serial_hw_int_cts
>
> serial_hw_init()
>
> include print -- output library
>
> function ascii_to_hex( byte in x ) return byte is
>
> if x > "9" then
> return x - ( "A" - 10 )
> else
> return x - "0"
> end if
>
> return x
> end function
>
> asm clrwdt ; clear watchdog
> option_reg = 7
> tmr0 = 242 ; 0.97mS/14.745600MHz passed
>
> _485_sense = RX_485
>
> forever loop
>
> if intcon_tmr0if == high then
> tmr0 = 242
> my_counter = my_counter + 1
> intcon_tmr0if = low
> end if
>
> if serial_hw_read ( dig1 ) then end if
> if serial_hw_read ( dig2 ) then end if
> if serial_hw_read ( dig3 ) then end if
> if serial_hw_read ( dig4 ) then end if
>
> if my_counter == 1 then
> digit_display ( 0,1,1,1,1,1,1,1)
> ; digit1 = ascii_to_hex ( dig1 )
> portB = seven_from_digit ( ascii_to_hex ( dig1 ) )
>
> elsif my_counter == 2 then
> digit_display ( 1,0,1,1,1,1,1,1)
> digit2 = ascii_to_hex ( dig2 )
> portB = seven_from_digit ( digit2 )
>
> elsif my_counter > 8 then
> my_counter = 0
>
> end if
>
> end loop
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---