Menu

Binary to ascii problem

Help
2008-06-28
2013-05-30
  • Nobody/Anonymous

    Okay with this:

    #chip 12F675, 4 'mhz 
    #config OSC=INTOSC, MCLRE=off, WDT=off
    '#mem 128 'Chip has 128 bytes
    'EEADRH = 0 

    Ser_Init 
    dim test as Word

    start: 
    test = ReadAD10(AN0)
    Bin2ascii (test_H)
    Bin2ascii (test)
    XMIT_RS232(test) 
    wait 2 sec
    goto start 

    Sub Ser_Init 
    #define baud 417 ;the us delay for 2400 baud rate 
    #define SerTxHigh Set GPIO.1 off 
    #define SerTxLow Set GPIO.1 On 
    dir GPIO.1 out
    dir GPIO.0 in 
    SerTxHigh ;Initial RS232 idle state 
    end sub 

    sub XMIT_PRINT (PrintData$) 
    PrintLen = PrintData(0) 
    if PrintLen = 0 then exit sub 
    'Write Data 
    for SysPrintTemp = 1 to PrintLen 
    XMIT_RS232(PrintData(SysPrintTemp)) 
    next 
    end sub 

    Sub XMIT_RS232(Xmit_Byte)#NR 
    SerTxLow ;Start bit 
    wait baud us 
    For cntr = 1 to 8 
    Rotate Xmit_Byte Right 
    If Status.C ON Then SerTxHigh 
    If Status.C Off Then SerTxLow 
    wait baud us 
    Next 
    SerTxHigh ;Stop bit 
    wait baud us 
    end sub 

    sub Bin2ascii(LCDValue )#NR 
    SERCEN = 0 
    SERDEC = 0 
    SERUN = 0 
    LCDValueTemp = 0 
    If LCDValue >= 100 Then 
    LCDValueTemp = LCDValue / 100 
    SERCEN = LCDValueTemp + 48 
    Xmit_RS232(SerCen) 'SerSend (1,SERCEN) 
    LCDValue = LCDValue - LCDValueTemp * 100 
    end if 
    IF LCDValueTemp > 0 OR LCDValue >= 10 then 
    LCDValueTemp = LCDValue / 10 
    SERDEC = LCDValueTemp + 48 
    Xmit_RS232(Serdec) 'SerSend (1,SERDEC) 
    LCDValue = LCDValue - LCDValueTemp * 10 
    end if 
    SERUN = LCDValue + 48 
    Xmit_RS232(Serun) 'SerSend (1,SERUN) 
    end sub 

    I'm getting communication, but nothing legible, the sensor I'm using outputs the temp/100 in voltage so that 75 degrees=.75vdc, 100degrees=1.00vdc linearly.

     
    • kent_twt4

      kent_twt4 - 2008-06-28

      Look at your main, you are immediately overwriting the BIN2ascii(ascii value-good) with the Xmit_RS232(binary value-bad).  Skip trying to read out a variable for now, and just read out a constant value.  Baby steps until you get the communication down, then add back the ReadAD10 part.

      Its all about experimentation, have you tried Xmit_Print ("Hello")?  Still can't get it to work?  Keep trying different baud delays, then different baud rates like 4800, or 9600.  Like I mentioned before, the 2400 baud at 4mhz was sketchy for whatever reason.

      Actually you should use the EEADRH = 0 when using the ReadAD10 (at least with the 12f675 and other small pin-out Pics), my mistake.

       
    • Nobody/Anonymous

      so I go:

      start: 
      test = 42  'ReadAD10(AN0) 
      Bin2ascii (test_H) 
      Bin2ascii (test) 
       
      wait 2 sec 
      goto start 

      is that right

       
    • Nobody/Anonymous

      do i do
      start:
      Xmit_Print ("Hello")
      wait 2 sec
      goto start

      and i should get hello in hyperterminal?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.