jackrude
Newbie level 6
- Joined
- Mar 22, 2012
- Messages
- 13
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Location
- United State
- Activity points
- 1,374
Hello all, I'm have trouble for displaying the second part of the message on to the LCD, it only display "temp controller, cur temp degree", it's not showing "temp =, deg C", please help me, i dont know it's the code problem or it's the hardware issue, this code is working on my demo board XL400, but is not working on my prototype,
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 #include<reg51.h> #define data P0 #define UPTEMP 45 #define DOWNTEMP 35 #define AL 50 sbit rs=P2^0; sbit rw=P2^1; sbit en=P2^2; sbit adc_read=P3^4; sbit adc_write=P3^3; sbit adc_intr=P3^5; sbit output=P3^7; sbit alam=P3^6; bit loadon=0; void delay(int time) { int i, j; for(i=0;i<127;i++) { for (j=0;j<time;j++); } } void lcd_data(unsigned char a) { rs =1; data=a; en =1; delay(5); en = 0; delay(5); } void lcd_cmd(unsigned char a) { rs=0; data=a; en=1; delay(1); en=0; delay(1); } void lcd_string (char * s) { while(*s) { lcd_data(*s); s++; } } void lcd_init() { lcd_cmd(0x38); lcd_cmd(0x0e); lcd_cmd(0x01); lcd_cmd(0x0c); lcd_cmd(0x80); } void pwmm(int i) { int j,k; output=1; for(j=0;j<i;j++) delay(5); k=10-i; output=0; for(j=0;j<k;j++) delay(5); } void main() { unsigned char val=0, temp=0; unsigned int x=0; float temp1; output=0; alam=1; rw=0; lcd_init(); lcd_string (" Temp controller" ); lcd_cmd(0xC0); lcd_string( "Cur temp degree"); adc_read = 1; adc_write = 1; delay(1000); lcd_cmd(0x01); while (1) { delay(100); adc_read=1; adc_write=0; delay(1); adc_write=1; while(adc_intr==1); adc_read=0; val=P1; temp=((float)val/255)*100.00; x+=(int)temp1; delay(10); delay (100); adc_read=1; adc_write=0; delay(1); adc_write=1; while(adc_intr==1); adc_read=0; val=P1; temp=((float)val/255)*100; x+=(int)temp1; delay(10); delay(100); adc_read=1; adc_write=0; delay(1); adc_write=1; while(adc_intr==1); adc_read=0; val=P1; temp=((float)val/255)*100; x+=(int)temp1; temp=x/3; x=0; if(temp>UPTEMP&&loadon==0) { output=1; loadon=1; } if(temp<=DOWNTEMP&&loadon==1) { pwmm(10); loadon=0; } if(temp>=AL) { alam=0; } lcd_cmd(0x80); lcd_string("TEMP="); lcd_data((temp/10)%10+48); lcd_data(temp%10+48); lcd_string(" DEG. C"); lcd_cmd(0xc0); if(loadon==1) { lcd_string("COOLER ON "); } else { lcd_string("COOLER OFF"); } lcd_cmd(0x80); } }
Last edited by a moderator: