Menu

What is wrong with this?

Help
2008-08-04
2013-05-30
  • Nobody/Anonymous

    Here is my code: I can't get it to respond

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

    Ser_Init
    dim test as Word
    dim test1 as word
    'dim test2 as word
    dim name as word

    Dir GPIO.0 in
    Dir GPIO.1 Out
    Dir GPIO.2 in
    Dir GPIO.3 In

    start:

    SerReceive gpio.3, Temp
            If Temp = 50 Then goto start
            If Temp = 52 Then output
       

    goto start

    sub output
    test = ReadAD10(AN0)
    Bin2ascii (test_H)
    Bin2ascii (test)

    test1 = ReadAD10(AN2)
    Bin2ascii (test1_H)
    Bin2ascii (test1)

    Temp = 50
    end sub

    'test2 = ReadAD10(AN3)
    'Bin2ascii (test2_H)
    'Bin2ascii (test2)

    'Xmit_Print ("bob")
    'XMIT_RS232(test)

    'wait 2 sec

    Sub Ser_Init
    #define baud 833 ;the us delay for 1200 baud rate 
    #define SerTxHigh Set GPIO.1 on
    #define SerTxLow Set GPIO.1 Off
    SerTxHigh ;Initial RS232 idle state
    #define RecAHigh GPIO.3 on
    #define RecALow GPIO.3 off
    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

     
    • kent_twt4

      kent_twt4 - 2008-08-05

      Where is the Ser_Receive, Temp coming from?  Another Pic? computer program? Hyperterminal?

      When evaluating the Temp statement, usually you are looking for something like <, <=, >, or >=.  So for your case, If Temp >= 52 Then goto output, everything else drops thru and goes back to start anyway.

       
    • Nobody/Anonymous

      computer (visual basic, I was wanting to use an exact number so that for later projects i could use this program to control all the outputs independently from the computer.

       
    • kent_twt4

      kent_twt4 - 2008-08-06

      Have a look over in the contributors forum, as there is a complete example there, including the RCV_RS232 subroutine which I finally ported over to GCBasic.

      You are soon to run out of stack space/variables for the 12f675, with all the word size functions being slung around.  Adjusting up to 12f683 would give you more room.  But, there are deeper concerns  that the project is being forced on the device, as opposed to the device being picked for the project.

      In addition to the size constraints of the 12f675, there seems to be a bug when trying for software serial comms with similar devices.  Was not personally able to work this out.  Suspect a status register, banking error, or some such, just not sure at the moment.

      Getting a higher pin count 18fxxxx device, with a hardware USART, and other peripherals that you require,  seems to be an easier less time consuming approach.  As a bonus, lots of stack and program space, plus the hardware USART in the contributors section would work,  and probably the SerSend and SerReceive too.

      Best of luck. Give a post back to the Forum if you pull it off with the 12f675.

       

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.