Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic18F4550 , Temperature sensor and Xbee - code correction

Status
Not open for further replies.

sara_strong

Newbie level 4
Joined
Nov 10, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Dubai,UAE
Activity points
1,350
My code is about interfacing a temperature sensor with PIC18F4550 microcontroller and then it is to be sent using Xbee module ZB series 2 to a gateway ConnectportX2.

Can anyone please tell me if there is something wrong with my code regarding the data transmission...like is there anything else i should add...i wasnt the xbee to read the values from port RA2 after its conversion to ASCII and then transmit it..anything to fix with the delays too!!??.

I am using MikroC pro for C coding


// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections


// Define Messages
char message0[] = "LCD Initialized";
char message1[] = "Body Temperature";
// String array to store temperature value to display
char *tempC = "000.0";
// Variables to store temperature values
int ANSEL;
unsigned int tempinC;
unsigned long temp_value;

void Display_Temperature() {
// convert Temp to characters
if (tempinC/10000)
// 48 is the decimal character code value for displaying 0 on LCD
tempC[0] = tempinC/10000 + 48;
else tempC[0] = ' ';
tempC[1] = (tempinC/1000)%10 + 48; // Extract tens digit
tempC[2] = (tempinC/100)%10 + 48; // Extract ones digit
// convert temp_fraction to characters
tempC[4] = (tempinC/10)%10 + 48; // Extract tens digit
// print temperature on LCD
Lcd_Out(2, 1, tempC);
}

void main() {
ANSEL = 0b00000100;
ADCON0 = 0b01001100; // Connect AN2 to S/H, select Vref=1.19V
TRISB = 0b00000000; // PORTb All Outputs
TRISA = 0b00001110; // PORTA All Outputs, Except RA3 and RA2

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize


Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,message0);
Delay_ms(1000);

Lcd_Out(1,1,message1); // Write message1 in 1st row

// Print degree character
Lcd_Chr(2,6,223);

// Different LCD displays have different char code for degree symbol
// if you see greek alpha letter try typing 178 instead of 223
Lcd_Chr(2,7,'C');

do {
temp_value = ADC_Read(2);
temp_value = temp_value*48876;
tempinC = temp_value/10000;
tempinC = tempinC*10;

Display_Temperature();

Delay_ms(1000); // Temperature sampling at 1 sec interval

if (UART1_Tx_Idle() == 1) {
UART1_Write(tempC);
}
} while(1);

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top