Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to read USART/UART in Swordfish

What PIC Program Devoloping software do you like most?

  • Swordfish (SE)

    Votes: 0 0.0%
  • MPLAB IDE ASM/C18

    Votes: 0 0.0%
  • Proton IDE

    Votes: 0 0.0%
  • mikroElektronika mikroBasic

    Votes: 0 0.0%
  • mikroElektronika mikroC

    Votes: 0 0.0%
  • Other

    Votes: 0 0.0%

  • Total voters
    0
  • Poll closed .
Status
Not open for further replies.

theo92

New Member
Hey guys, how to read, I mean using what function, I can read USART?

I can send something to PC UART via PICKit2 UART tool, I can see you a small part....
Code:
..................................................
Temp:24.78
Humid:65.64%
Dew Point:17.90
..................................................
..................................................
Temp:24.68
Humid:65.63%
Dew Point:17.81
..................................................
..................................................
Temp:24.76
Humid:65.67%
Dew Point:17.90
..................................................
..................................................
Temp:24.68
Humid:65.71%
Dew Point:17.84
..................................................
..................................................
Temp:24.68
Humid:65.71%
Dew Point:17.84
..................................................
..................................................
Temp:24.68
Humid:65.71%
Dew Point:17.83
..................................................
..................................................
Temp:24.76
Humid:65.67%
Dew Point:17.89
..................................................
..................................................
Temp:24.82
Humid:65.74%
Dew Point:17.97
..................................................
..................................................
Temp:24.72
Humid:65.75%
Dew Point:17.88
..................................................
..................................................
Temp:24.66
Humid:65.62%
Dew Point:17.80
..................................................
..................................................
Temp:24.76
Humid:65.64%
Dew Point:17.88
..................................................
..................................................
Temp:24.80
Humid:65.76%
Dew Point:17.96
..................................................
..................................................
Temp:24.79
Humid:65.70%
Dew Point:17.94
..................................................
..................................................
Temp:24.79
Humid:65.70%
Dew Point:17.94
..................................................
..................................................
Temp:24.96
Humid:65.73%
Dew Point:18.10
..................................................
..................................................
Temp:24.96
Humid:65.67%
Dew Point:18.08
..................................................
..................................................
Temp:24.93
Humid:65.76%
Dew Point:18.08
..................................................
..................................................
Temp:24.82
Humid:65.65%
Dew Point:17.94
..................................................
..................................................
Temp:24.93
Humid:65.73%
Dew Point:18.08
..................................................
..................................................
Temp:24.98
Humid:65.68%
Dew Point:18.11
..................................................
..................................................
Temp:24.78
Humid:65.67%
Dew Point:17.91
..................................................
..................................................
Temp:24.97
Humid:65.67%
Dew Point:18.10
..................................................
..................................................
Temp:24.79
Humid:65.59%
Dew Point:17.91
..................................................
..................................................
Temp:24.83
Humid:65.59%
Dew Point:17.94
..................................................
..................................................
Temp:24.73
Humid:65.49%
Dew Point:17.83
..................................................
..................................................
Temp:24.83
Humid:65.50%
Dew Point:17.93
..................................................
..................................................
Temp:24.90
Humid:65.57%
Dew Point:18.00
..................................................
..................................................
Temp:24.76
Humid:65.49%
Dew Point:17.86
..................................................
..................................................
Temp:24.79
Humid:65.50%
Dew Point:17.88
..................................................
..................................................
Temp:24.96
Humid:65.44%
Dew Point:18.03
..................................................
..................................................
Temp:24.93
Humid:65.43%
Dew Point:18.00
..................................................
..................................................
Temp:24.96
Humid:65.49%
Dew Point:18.04
..................................................
..................................................
Temp:24.93
Humid:65.40%
Dew Point:17.99
..................................................
..................................................
Temp:24.82
Humid:65.41%
Dew Point:17.89
..................................................
..................................................
Temp:24.93
Humid:65.46%
Dew Point:18.00
..................................................

Now, this process continues as long as UART link is connected or power is up.

I dont want it. I want when I'll send something (suppose I send "T") via PICKit2 UART Tool to the PIC18F2550 based circuity, It'll send something (suppose Temp:xxxx, Humid:xxx, Dew Point:xxxx) to PC.

Please tell me how to do this task. I think it should be easy....pls help

I dont know is it a interrupt or not, I dont have the interrupt concept.
 
Please tell me how to do this task. I think it should be easy....pls help

I dont know is it a interrupt or not, I dont have the interrupt concept.

You don't need interrupts to do it, and it's VERY simple.

Wait in a loop for a character to be received from the UART, then check if it's 'T', if it is, then jump to a subroutine that sends the data you need out the serial port. If it's not 'T' (and when the subroutine returns) go back to the wait loop.
 
Thanks Nigel, I get ya into work.
 
Last edited:
I've again stucked in one thing..

Is it possible to use 'while...wend' loop more than one time in a program. When it gets the while...wend loop once, it continues executing it over and over...so is it not possible to create one more while...wend loop.

My program has two part, one is for printing some data(temp., humid.,dew point)to LCD which continues and updates the value in every momment until shutting down the power....Another part is writing the data to UART...But It's not in every momment..when the PIC receives a string(suppose "T"), it sends the data via UART.

The first part of my program is all right. But problem appears from here...

Code:
 NoError = Sensirion.Sensirion_Get_Temp_Hum(temperature, humidity)
    If NoError Then
        //Temperature Calcutation
        buft = temperature * 100
        TempA = buft / 100
        TempB = buft Mod 100
        LCD.WriteAt(1,1,DecToStr(TempA,2),".",DecToStr(TempB,2), 223,"C")
        //Humidity Calculation
        bufh = humidity * 100
        HumA = bufh / 100
        HumB = bufh Mod 100
        LCD.WriteAt(1,9,DecToStr(HumA,2),".",DecToStr(HumB,2),"%")
        //Dew Point Calculation
        dew_point = Sensirion.Sensirion_Get_Dew_Point(temperature, humidity)       
        bufd = dew_point * 100
        DewA = bufd/100
        DewB = bufd Mod 100
        LCD.WriteAt(2,1, DecToStr(DewA,2),".",DecToStr(DewB,2),223,"C")
      Else
        LCD.WriteAt(1,1,"Device Not Found")
        LCD.WriteAt(2,1,"Check Connection")
      End If
      
        WaitForstr("T")       //HELP YA BABY
        
        SetBaudrate(br19200)
      
      USART.Write("*******************", 13, 10)
      USART.Write("Temperature =", DecToStr(TempA,2),".",DecToStr(TempB,2), 13, 10)
      USART.Write("Humidity =", DecToStr(HumA,2),".",DecToStr(HumB,2), 13, 10)
      USART.Write("Dew Point =", DecToStr(DewA,2),".",DecToStr(DewB,2), 13, 10)
      USART.Write("*******************", 13, 10) 
      Wend


When the PIC doesnt receive anything via UART the program stops and LCD shows the previous value, and no update.

I want to run LCD and UART individually so that LCD can update everytime. While The uART should only send data when it gets a valid string via Rx .

Any help?
 
Enclose both in the same loop, and check for each in the loop, something like this:

Code:
While
    If LCD_Requires_Updating Then Gosub UpdateLCD;
    If Serial_Data_Received Then Gosub CheckSerialPort;
Wend
 
Status
Not open for further replies.

Latest threads

Back
Top