condition not working


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    37

    Default condition not working

    Following code gathers 4 bit ADC value from serial port constantly. Only 2 values are available 3265 approx (actually 3.265) and 1625approx ( actually 1.265). The program checks for first bit (rec[1] in code) in if loop and generates alarm. But despite being value of rec[1]=3 if loop is not executed. I have tried several approaches but to no avail. Please advice.
    Chip used is 16F88.

    INCLUDE "modedefs.bas"


    DEFINE OSC 8
    OSCCON=%01110000 ' INTRC = 8MHz


    ANSEL=$00
    CMCON = %00000111
    TRISA=$00
    PORTA=0


    Define LCD_DREG PORTA
    Define LCD_DBIT 0 '(LCD pins D4-D7 to PORTA.0 to 3)
    DEFINE LCD_BITS 4
    Define LCD_RSREG PORTA
    Define LCD_RSBIT 4
    Define LCD_EREG PORTA
    Define LCD_EBIT 6
    DEFINE LCD_LINES 2 ; Set number of LCD lines (1 ~ 4)
    DEFINE LCD_COMMANDUS 2000 ; Set 2-millisecond command period
    DEFINE LCD_DATAUS 50 ; Set data delay period


    Define CCP1_PIN PORTB.0 ;connected to piezo for alarm
    CCP1CON=%00001100
    Trisb.0=0
    portb.0=0


    DEFINE HSER_RCSTA 90h


    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    ' Enable serial port and continuous receive


    x var byte
    rec Var Byte[4]
    y var byte
    Lcdout $fe,1,"Serial to Parallel"
    pause 200
    Lcdout $fe,1
    y=0
    x=0


    Loop:


    y=y+1
    Hserin [rec[y]]
    x=rec[1]


    if x=3 then
    Lcdout $fe, $80, "alarm"
    HPWM 1,125,1000 ' Send a 50% duty cycle PWM signal at 1KHz
    endif


    Hserout [rec[y]] 'display on hyperterminal
    Lcdout $fe, $14, rec[y] 'display on LCD
    Lcdout $fe, $14, Dec1 x




    'when 4 bits of ADC are received,re-initialize y & LCD
    if y=4 then
    y=0
    Lcdout $fe,2
    endif



    Goto Loop
    End

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: condition not working

    Hi,
    It seems to me like you are receiving ASCII so if you want to check for the 'digit' 3 you should compare x to 51 which is the ASCII code for '3'

    /Henrik.

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: condition not working

    Try this:

    Change "rec Var Byte[4]" to "rec Var Byte[5]
    Last edited by sayzer; - 2nd April 2012 at 09:06. Reason: typo
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Jun 2006
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: condition not working

    right that does it.simplest of things to forget....

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts