vgavale
Newbie level 2
- Joined
- Feb 28, 2015
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 91
the code is running but it is not displaying temperature value.
following is code
following is code
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 /********************************************************************************/ /*This program demonstrates the interfacing of LCD to PIC18F4550 microcontroller*/ /********************************************************************************/ /* LCD DATA port----PORT D signal port------PORT E rs-------RE0 rw-------RE1 en-------RE2 */ #include <p18f4550.h> #include<stdlib.h> //LCD data pins connected to PORTD and control pins connected to PORTE #define LCD_DATA PORTD //LCD data port #define ctrl PORTE //LCD signal port #define en PORTEbits.RE2 // enable signal #define rw PORTEbits.RE1 // read/write signal #define rs PORTEbits.RE0 // register select signal #define BUSY PORTDbits.RD7 #define Channel0 0b00000000 #define Channel1 0b00000100 void ADC_Init(); void Select_Channel(unsigned char Channel); void Get_ADC_Result(void); void Start_Conversion(void); void myMsDelay (unsigned int time); //LCD function definitions void LCD_Busy(void); void LCD_cmd(unsigned char cmd); void init_LCD(void); void LCD_write(unsigned char data); void LCD_write_string( char *str); //void LCD_itoa(unsigned float t,arr[5]) /*The following lines of code perform interrupt vector relocation to work with the USB bootloader. These must be used with every application program to run as a USB application.*/ extern void _startup (void); #pragma code _RESET_INTERRUPT_VECTOR = 0x1000 void _reset (void) { _asm goto _startup _endasm } #pragma code #pragma code _HIGH_INTERRUPT_VECTOR = 0x1008 void high_ISR (void) { } #pragma code #pragma code _LOW_INTERRUPT_VECTOR = 0x1018 void low_ISR (void) { } #pragma code //Function to generate delay void myMsDelay (unsigned int time) { unsigned int i, j; for (i = 0; i < time; i++) for (j = 0; j < 710; j++);/*Calibrated for a 1 ms delay in MPLAB*/ } // Function to initialise the LCD void init_LCD(void) { LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode myMsDelay(15); LCD_cmd(0x01); // clear LCD myMsDelay(15); LCD_cmd(0x0C); // cursor off myMsDelay(15); LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position myMsDelay(15); } //Function to pass command to the LCD void LCD_cmd(unsigned char cmd) { LCD_DATA = cmd; rs = 0; rw = 0; en = 1; myMsDelay(15); en = 0; myMsDelay(15); return; } //Function to write data to the LCD void LCD_write(unsigned char data) { LCD_DATA = data; rs = 1; rw = 0; en = 1; myMsDelay(15); en = 0; myMsDelay(15); return ; } //Function to split the string into individual characters and call the LCD_write function void LCD_write_string( char *str) //store address value of the string in pointer *str { int i = 0; while (str[i] != 0) { LCD_write(str[i]); // sending data on LCD byte by byte myMsDelay(15); i++; } return; } void ADC_Init() { ADCON0=0b00000000; //A/D Module is OFF no channel selected ADCON1=0b00001110; // Reference as VDD & VSS, AN0 set as analog pins ADCON2=0b10001110; // Result is right Justified //Acquisition Time 2TAD //ADC Clk FOSC/64 ADCON0bits.ADON=1; //Turn ON ADC module } void Select_Channel(unsigned char Channel) { ADCON0=ADCON0 & 0b11000001; ADCON0=ADCON0 | Channel; //selecting channel no 0 } void Start_Conversion() { ADCON0bits.GO=1; } //If you do not wish to use adc conversion interrupt you can use this //to do conversion manually. It assumes conversion format is right adjusted void Get_ADC_Result() { unsigned float t; char arr[5]; unsigned char val,pot0[6]; unsigned int ADC_Result=0; while(ADCON0bits.GO); ADC_Result=ADRESL; ADC_Result|=((unsigned int)ADRESH) << 8; t=(ADRESH * 0.48876); //Convert to Degree Celcius - ADRES (16bit) is the output of ADC } void main(void) { unsigned float t; unsigned int adc_val; unsigned char arr[5]; char var1[] = "Temperature:"; ADCON1 = 0x0F; //Configuring the PORTE pins as digital I/O TRISD = 0x00; //Configuring PORTD as output TRISE = 0x00; //Configuring PORTE as output init_LCD(); // initialization of LCD myMsDelay(5); // delay of 5 mili seconds LCD_write_string(var1); Get_ADC_Result(); LCD_cmd(0xC0); LCD_write_string('itoa(t,arr[5])'); LCD_write(0xDF); * * * * LCD_write('C'); while(1) { Select_Channel(Channel0); Start_Conversion(); Get_ADC_Result(); } //LCD_cmd(0xC0); //LCD_write_string(var1); // Move cursor to line 2 position 1 ** * //*LCD_write('t'); * * * * *// Display the temperature* * * * *// LCD_write(0xDF); * * * //* LCD_write('C'); }
Last edited by a moderator: