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.

my circuit is not functioning...

Status
Not open for further replies.

yjia

Newbie level 3
Newbie level 3
Joined
Jul 27, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
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:

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 :p
regards,
 

Rx pin should be configured as input pin if you need to receive data from PC. There are so many while(1) loops inside the functions and the execution is getting stuck in the first while(1) it encounters after the while(1) in the main().


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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;
       }

 
Last edited:

alright the while loop is to blink those LEDs..any others method instead of using while loop to blink the LED?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top