flamesier
Newbie level 6
my mikroC software seems to be outdated. V6.0.0
can anyone help to convert this code to hex file please.
need it badly.
thanks.
can anyone help to convert this code to hex file please.
need it badly.
thanks.
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 222 223 224 225 226 227 228 // VARIABLES char second = 0; char second_old = 0; char minute = 0; char minute_ten = 0; char minute_one = 0; char hour = 0; char hour_ten = 0; char hour_one = 0; char counter_1=0; char counter_2=0; unsigned temp = 0; char temp_ten=0; char temp_one=0; char temp_neg=0; char blink=0; char i=0; void send_to_max7219(char address,char data) { PORTC.F6 = 0; // LOAD(CS) LINE LOW Spi_Write(address); Spi_Write(data); PORTC.F6 = 1; // LOAD(CS) LINE HIGH } void init_MAX7219() { send_to_max7219(0x09,0xFF);// BCD Mode Code B send_to_max7219(0x0A,0x0F);// INTENSITY MAX send_to_max7219(0x0B,0x03);// SCAN ONLY DIGITS 0,1,2,3 send_to_max7219(0x0C,0x01);// TURN ON send_to_max7219(0x00,0x0F);// TEST OFF } void show_temp() { // READ AN0 INPUT 50 TIMES CUMULATIVELY temp=0; for (i=0;i<=49;i++) { temp = temp+ Adc_Read(0); delay_ms(1); } temp=temp/50; //CALCULATE THE AVERAGE temp = temp*4.57;//CALCULATE THE SENSOR OUTPUT in mV // TEMPERATURE POSITIVE OR NEGATIVE? if (temp>=2730) { temp = temp-2730; temp_neg=0;} else {temp=2730-temp;temp_neg=1;} // CONVERT TEMPERATURE VALUE INTO BCD FORMAT temp=Dec2Bcd16(temp); // MAX7219 NO DECODE MODE send_to_max7219(0x09,0x00); // DISPLAY THE MINUS SIGN IF TEMP IS NEGATIVE if (temp_neg) { send_to_max7219(0x01,0x01); } else { send_to_max7219(0x01,0x00); } // SEPERATE THE TEMPERATURE DIGITS temp_one=(temp>>4)&0b00001111; temp_ten=(temp>>8)&0b00001111; // DISPLAY THE TEMPERATURE DIGITS if (temp_one==0x00) {send_to_max7219(0x03,0x7E);} else if (temp_one==0x01) {send_to_max7219(0x03,0x30);} else if (temp_one==0x02) {send_to_max7219(0x03,0x6D);} else if (temp_one==0x03) {send_to_max7219(0x03,0x79);} else if (temp_one==0x04) {send_to_max7219(0x03,0x33);} else if (temp_one==0x05) {send_to_max7219(0x03,0x5B);} else if (temp_one==0x06) {send_to_max7219(0x03,0x5F);} else if (temp_one==0x07) {send_to_max7219(0x03,0x70);} else if (temp_one==0x08) {send_to_max7219(0x03,0x7F);} else if (temp_one==0x09) {send_to_max7219(0x03,0x7B);} if (temp_ten==0x00) {send_to_max7219(0x03,0x7E);} else if (temp_ten==0x01) {send_to_max7219(0x02,0x30);} else if (temp_ten==0x02) {send_to_max7219(0x02,0x6D);} else if (temp_ten==0x03) {send_to_max7219(0x02,0x79);} else if (temp_ten==0x04) {send_to_max7219(0x02,0x33);} else if (temp_ten==0x05) {send_to_max7219(0x02,0x5B);} else if (temp_ten==0x06) {send_to_max7219(0x02,0x5F);} else if (temp_ten==0x07) {send_to_max7219(0x02,0x70);} else if (temp_ten==0x08) {send_to_max7219(0x02,0x7F);} else if (temp_ten==0x09) {send_to_max7219(0x02,0x7B);} // DISPLAY THE DEGREE SIGN send_to_max7219(0x04,0x62); } void main() { // INITIALIZE SPECIAL FUNCTION REGISTERS ADCON1=0b00001110; // SELECT THE ANALOG INPUTS TRISC = 0b00010000; // ASSIGN DIRECTIONS FOR PORTC TRISB = 0b11111111; // ASSIGN DIRECTIONS FOR PORTB TRISA = 0b00000001; // ASSIGN DIRECTIONS FOR PORTA PORTC.F6 = 1; //LOAD(CS) LINE IS INITIALLY LOW // INIT HW SPI Spi_Init_Advanced(MASTER_OSC_DIV16,DATA_SAMPLE_MIDDLE,CLK_IDLE_LOW,LOW_2_HIGH); // INIT SW I2C Soft_I2C_Config(&PORTB, 1, 0); while(1) { init_MAX7219(); // READ SECOND, MINUTE and HOUR INFO FROM DS1307 Soft_I2C_Start(); Soft_I2C_Write(0xD0); Soft_I2C_Write(0x00); Soft_I2C_Start(); Soft_I2C_Write(0xD1); second = Soft_I2C_Read(1); minute = Soft_I2C_Read(1); hour = Soft_I2C_Read(0); Soft_I2C_Stop(); // SEPERATE THE HOUR AND MINUTE DIGITS hour_one = 0b00001111 & hour; hour_ten = (hour >> 4) & 0b00001111; minute_one = 0b00001111 & minute; minute_ten = (minute >> 4) & 0b00001111; // BLINKING AND TEMP. DISPLAY PERIOD if (second != second_old) { // DETECT A SECOND counter_1++; counter_2++; second_old=second; if (counter_1==1) { // BLINK EVERY 1 SECOND counter_1=0; blink=~blink; } if (counter_2==15) { // DISPLAY TEMP EVERY 15 SECONDS counter_2=0; show_temp(); delay_ms(3000); // DISPLAY FOR THREE SECONDS send_to_max7219(0x09,0xFF); // SET BCD CODE B } } // MANUALLY SHOW TEMP IF SW2 IS PRESSED if (PORTB.F3==0) { counter_2=0; show_temp(); delay_ms(3000); send_to_max7219(0x09,0xFF); // SET BCD CODE B } // DISPLAY THE HOUR DIGITS if (hour_ten == 0x00) { // IF THE DECIMAL DIGIT IS 0 send_to_max7219(0x01,0x0F);} // THEN DISPLAY NOTHING IN FIRST DIGIT else { send_to_max7219(0x01,hour_ten);} if (blink==0xFF) { hour_one|=0b10000000;} // DETERMINE THE DOT STATUS OF THE 2nd DIGIT else { hour&=0b01111111;} send_to_max7219(0x02,hour_one); // DISPLAY THE MINUTE DIGITS if (blink==0xFF) { minute_ten|=0b10000000;} // DETERMINE THE DOT STATUS OF THE 3th DIGIT else { minute_ten&=0b01111111;} send_to_max7219(0x03,minute_ten); send_to_max7219(0x04,minute_one); // INCREASE THE HOUR IF SW IS PRESSED hour_one&=0b01111111; if (PORTB.F2==0) { if (hour_one<=0x08) { if ((hour_ten==0x02) && (hour_one==0x03)) { hour_one=0; hour_ten=0; } else { hour_one++;} } else {hour_one=0x00; if (hour_ten<=0x1) { hour_ten++;} else { hour_ten=0x00;} } // WRITE THE NEW HOUR VALUE TO DS1307 hour_ten = (hour_ten<<4)&0b11110000; hour = hour_one|hour_ten; Soft_I2C_Start(); Soft_I2C_Write(0xD0); Soft_I2C_Write(0x02); Soft_I2C_Write(hour); Soft_I2C_Stop(); do {} while (PORTB.F2==0) ; // SW DEBOUNCE } // INCREASE MINUTE IF SW3 IS PRESSED minute_ten&=0b01111111; if (PORTB.F4==0) { if (minute_one<=0x08) { minute_one++; } else { if ((minute_ten==0x05) && (minute_one==0x09)) { minute_one=0x00; minute_ten=0x00; } else if (minute_ten<=0x05) { minute_ten++; minute_one=0x00;} else { minute_ten=0x00; minute_one=0x00;} } // WRITE THE NEW MINUTE VALUE TO DS1307 minute_ten = (minute_ten<<4)&0b11110000; minute = minute_one|minute_ten; Soft_I2C_Start(); Soft_I2C_Write(0xD0); Soft_I2C_Write(0x00); Soft_I2C_Write(0x00); Soft_I2C_Write(minute); Soft_I2C_Stop(); do {} while (PORTB.F4==0); // SW DEBOUNCE } } }
Last edited by a moderator: