yjia
Newbie level 3
- Joined
- Jul 27, 2013
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 26
i wrote a program to my project with the tittle fire tracking system with pc monitoring, but i found that the system is not functioning, LEDs are connected to port B, lm35 as inputs are connected to port D, port c as the output connecting with rs232 to transfer the date to computer..hyperterminal used to collecting the data from the system. here is the code:
Kindly help folks
regards,
Code:
#define LEDA PORTB.F0
#define LEDB PORTB.F1
#define LEDC PORTB.F2
#define LEDD PORTB.F3
#define Buzzer PORTB.F4
#include "built_in.h"
float temp, tempA, tempB, tempC, tempD;
int n;
void adc_conversion(unsigned int sensor_num);
const unsigned char msg1[] = "PIC16F877A";
const unsigned char msg2[] = "TEMP UNIT(v2)";
unsigned char i=0;
unsigned int adc_data = 0x00;
unsigned char buffer[16];
int sensor_num;
unsigned int temp_res;
void wait() {
delay_ms(1000);
}
void main()
{
TRISA = 0xFF;
TRISB = 0;
TRISC = 0;
TRISD = 0xFF;
//PORTB = 0x00;
UART1_Init(9600); // Initalize USART (9600 baud rate, 1 stop bit, ...
//Delay_ms(100); // wait uart module to se
ADCON0 = 0x81;
//Fosc/64 is Selected
//Channel-0 is Selected
//Analog-to-Digital Converter Module is Powered Up
ADCON1 = 0xC0;
//A/D Result Format Select Bit Right Justified
//and AN0 Channel as Analog Channel
while(1)
{
ADCON0 = 0x81; //First Channel
sensor_num = 1;
adc_conversion(sensor_num);
ADCON0 = 0x89;
sensor_num = 2;
adc_conversion(sensor_num);
ADCON0 = 0x91;
sensor_num = 3;
adc_conversion(sensor_num);
ADCON0 = 0x99;
sensor_num = 4;
adc_conversion(sensor_num);
}
}
void adc_conversion(unsigned int sensor_num){
sensor_num--;
ADCON0 = (0x81)|(sensor_num<<3);
delay_ms(1000);
ADCON0.GO = 1; //Start Conversion
while(ADCON0.GO == 1); {
adc_data = ADRESH & 0x00FF;
adc_data = adc_data<<8;
adc_data = adc_data | ADRESL;
adc_data = (500)*adc_data/1023;
//adc_data = temp;
switch(sensor_num){
case 0:
adc_data=tempA;
break;
case 1:
adc_data=tempB;
break;
case 2:
adc_data=tempC;
break;
case 3:
adc_data=tempD;
break;
}
}
if ((tempA >= 10) ) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
LEDB = 0; // * and temperature B less than 35'C *
LEDC = 0;
LEDD = 0;
Buzzer = 1;
}
else if ((tempB >= 10) ) {
// * LED B and Fan B activated only for *
LEDA = 0; // * temperature A less than 40'C and *//lebih 22=26
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
LEDC = 0;
LEDD = 0;
Buzzer = 1;
}
else if ((tempC >= 10) ) {
LEDA = 0;
LEDB = 0;
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
LEDD = 0;
Buzzer = 1;
}
else if ((tempD >= 10) ) {
LEDA = 0;
LEDB = 0;
LEDC = 0;
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempA==tempB)&&(tempA >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
LEDC = 0;
LEDD = 0;
Buzzer = 1;
}
else if ((tempA==tempC)&&(tempA >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
LEDB = 0;
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
LEDD = 0;
Buzzer = 1;
}
else if ((tempA==tempD)&&(tempA >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
LEDB = 0;
LEDC = 0;
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempB==tempC)&&(tempB >= 10)) {
LEDA = 0;
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
LEDD = 0;
Buzzer = 1;
}
else if ((tempB==tempD)&&(tempB >= 10)) {
LEDA = 0;
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
LEDC = 0;
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempD==tempC)&&(tempD >= 10)) {
LEDA = 0;
LEDB = 0;
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempA==tempB==tempC)&&(tempA >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
LEDD = 0;
Buzzer = 1;
}
else if ((tempB==tempC==tempD)&&(tempB >= 10)) {
LEDA = 0;
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempC==tempD==tempA)&&(tempC >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
LEDB = 0;
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempD==tempA==tempB)&&(tempD >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
LEDC = 0;
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else if ((tempA==tempB==tempC==tempD)&&(tempA >= 10)) {
while(1){
LEDA = 1;
delay_ms(1000);
LEDA=0;
}
while(1){
LEDB = 1;
delay_ms(1000);
LEDB=0;
}
while(1){
LEDC = 1;
delay_ms(1000);
LEDC=0;
}
while(1){
LEDD = 1;
delay_ms(1000);
LEDD=0;
}
Buzzer = 1;
}
else {
LEDA = 0;
LEDB = 0;
Buzzer = 0;
}
do
{
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
UART1_write(Lo(temp_res)); // Send lower 8 bits to UART
Delay_ms(100);
UART1_write(Hi(temp_res)); // Send upper 8 bits to UART
PORTB = Lo(temp_res); // Send lower 8 bits to PORTB
PORTC = Hi(temp_res); // Send 2 most significant bits to RC7, RC6
}while(1);
}
Kindly help folks
regards,