Functions | |
void | ht1632_fill (uns8 colour) |
void | ht1632_fill2 (uns8 colour) |
void | ht1632_init (uns8 hw_config) |
void | ht1632_send_command (uns8 command) |
void | ht1632_set_brightness (uns8 brightness) |
void | ht1632_set_pixel (uns8 x, uns8 y, uns8 colour) |
void | ht1632_setup_io () |
void | ht1632_write (uns8 mem_addr, uns8 data) |
void ht1632_fill | ( | uns8 | colour | ) |
00326 { 00327 uns8 mem_address; 00328 uns8 fill; 00329 00330 if (colour) { 00331 fill = 0b00001111; 00332 } else { 00333 fill = 0b00000000; 00334 } 00335 00336 for(mem_address = 0 ; mem_address < 96 ; mem_address++) { 00337 ht1632_write(mem_address, fill); 00338 } 00339 }
void ht1632_fill2 | ( | uns8 | colour | ) |
00341 { 00342 00343 uns16 count; 00344 ht1632_send_command(HT1632_CMD_LEDS_OFF); 00345 clear_pin(ht1632_cs1_port, ht1632_cs1_pin); 00346 00347 // send WR command 00348 00349 // send 1 00350 set_pin (ht1632_data_port, ht1632_data_pin); 00351 // pulse wr 00352 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00353 set_pin (ht1632_wr_port, ht1632_wr_pin); 00354 00355 // send 0 00356 clear_pin (ht1632_data_port, ht1632_data_pin); 00357 // pulse wr 00358 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00359 set_pin (ht1632_wr_port, ht1632_wr_pin); 00360 00361 // send 1 00362 set_pin (ht1632_data_port, ht1632_data_pin); 00363 // pulse wr 00364 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00365 set_pin (ht1632_wr_port, ht1632_wr_pin); 00366 00367 // send mem address of zero 00368 clear_pin(ht1632_data_port, ht1632_data_pin); 00369 00370 // write mem addr, bits 6 -> 0 00371 for(count = 0 ; count < 7 ; count++) { 00372 00373 //change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6)); 00374 // pulse wr 00375 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00376 set_pin (ht1632_wr_port, ht1632_wr_pin); 00377 // shift mem addr along 00378 00379 } 00380 if (colour) { 00381 set_pin(ht1632_data_port, ht1632_data_pin); 00382 } else { 00383 clear_pin(ht1632_data_port, ht1632_data_pin); 00384 } 00385 // we need to toggle 384 times 00386 00387 for(count = 0 ; count < 384 ; count++) { 00388 // pulse wr 00389 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00390 set_pin (ht1632_wr_port, ht1632_wr_pin); 00391 // shift mem addr along 00392 00393 } 00394 // reset CS 00395 00396 set_pin(ht1632_cs1_port, ht1632_cs1_pin); 00397 ht1632_send_command(HT1632_CMD_LEDS_ON); 00398 00399 00400 }
void ht1632_init | ( | uns8 | hw_config | ) |
00075 { 00076 00077 ht1632_send_command(HT1632_CMD_SYS_DISABLE); 00078 // ht1632_send_command(HT1632_CMD_PMOS_16_COMMON); // Correct hardware layout for the board 00079 // ht1632_send_command(HT1632_CMD_PMOS_8_COMMON); // Correct hardware layout for the board 00080 ht1632_send_command(hw_config); 00081 ht1632_send_command(HT1632_CMD_CLK_MASTER_MODE); // We are the master 00082 ht1632_send_command(HT1632_CMD_SYS_ENABLE); 00083 ht1632_send_command(HT1632_CMD_LEDS_ON); //led on 00084 }
void ht1632_send_command | ( | uns8 | command | ) |
00086 { 00087 00088 uns8 count; 00089 00090 clear_pin(ht1632_cs1_port, ht1632_cs1_pin); 00091 clear_pin(ht1632_cs2_port, ht1632_cs2_pin); 00092 clear_pin(ht1632_cs3_port, ht1632_cs3_pin); 00093 clear_pin(ht1632_cs4_port, ht1632_cs4_pin); 00094 00095 // send command 00096 // send 1 00097 set_pin (ht1632_data_port, ht1632_data_pin); 00098 // pulse wr 00099 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00100 set_pin (ht1632_wr_port, ht1632_wr_pin); 00101 00102 // send 0 00103 clear_pin (ht1632_data_port, ht1632_data_pin); 00104 // pulse wr 00105 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00106 set_pin (ht1632_wr_port, ht1632_wr_pin); 00107 00108 // send 0 00109 clear_pin (ht1632_data_port, ht1632_data_pin); 00110 // pulse wr 00111 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00112 set_pin (ht1632_wr_port, ht1632_wr_pin); 00113 00114 // command bits 7 - 0 00115 for(count = 0 ; count < 8 ; count++) { 00116 00117 if (test_bit(command, 7)) { 00118 set_pin(ht1632_data_port, ht1632_data_pin); 00119 } else { 00120 clear_pin(ht1632_data_port, ht1632_data_pin); 00121 } 00122 00123 // pulse wr 00124 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00125 set_pin (ht1632_wr_port, ht1632_wr_pin); 00126 // shift mem addr along 00127 command = command << 1; 00128 } 00129 00130 // the don't care pulse 00131 00132 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00133 set_pin (ht1632_wr_port, ht1632_wr_pin); 00134 00135 00136 set_pin(ht1632_cs1_port, ht1632_cs1_pin); 00137 set_pin(ht1632_cs2_port, ht1632_cs2_pin); 00138 set_pin(ht1632_cs3_port, ht1632_cs3_pin); 00139 set_pin(ht1632_cs4_port, ht1632_cs4_pin); 00140 }
void ht1632_set_brightness | ( | uns8 | brightness | ) |
00206 { 00207 // allows level 0 - 15 00208 ht1632_send_command(0b10100000 | (brightness & 0b00001111)); 00209 }
void ht1632_set_pixel | ( | uns8 | x, | |
uns8 | y, | |||
uns8 | colour | |||
) |
00211 { 00212 00213 uns8 common, panel, led_in_panel, inverted_x, out, mem_addr, bit_in_mem_addr, count, data; 00214 00215 // first calculate memory address 00216 00217 // y location on panels is top left based 00218 00219 common = 15 - y; 00220 00221 /* Previous calculations: 00222 panel = x / 8; // which panel of the three is it that we need to change? 00223 led_in_panel = x - (panel * 8); 00224 inverted_x = 7 - led_in_panel; 00225 out = panel * 8 + led_in_panel; //inverted_x; 00226 mem_addr = out * 4 + common / 4; 00227 */ 00228 bit_in_mem_addr = common & 0b00000011; 00229 00230 00231 mem_addr = x * 4 + common / 4; 00232 00233 00234 clear_pin(ht1632_cs1_port, ht1632_cs1_pin); 00235 00236 // send WR command 00237 00238 // send 1 00239 set_pin (ht1632_data_port, ht1632_data_pin); 00240 // pulse wr 00241 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00242 set_pin (ht1632_wr_port, ht1632_wr_pin); 00243 00244 // send 0 00245 clear_pin (ht1632_data_port, ht1632_data_pin); 00246 // pulse wr 00247 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00248 set_pin (ht1632_wr_port, ht1632_wr_pin); 00249 00250 // send 1 00251 set_pin (ht1632_data_port, ht1632_data_pin); 00252 // pulse wr 00253 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00254 set_pin (ht1632_wr_port, ht1632_wr_pin); 00255 00256 // write mem addr, bits 6 -> 0 00257 for(count = 0 ; count < 7 ; count++) { 00258 if (test_bit(mem_addr, 6)) { 00259 set_pin(ht1632_data_port, ht1632_data_pin); 00260 } else { 00261 clear_pin(ht1632_data_port, ht1632_data_pin); 00262 } 00263 00264 //change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6)); 00265 // pulse rd 00266 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00267 set_pin (ht1632_wr_port, ht1632_wr_pin); 00268 00269 // shift mem addr along 00270 mem_addr = mem_addr << 1; 00271 } 00272 00273 // Retrieve 4 bits 00274 // read clocked out on falling edge of RD 00275 00276 make_input(ht1632_data_port, ht1632_data_pin); 00277 00278 for(count = 0 ; count < 4 ; count++) { 00279 // pulse rd 00280 clear_pin(ht1632_rd_port, ht1632_rd_pin); 00281 00282 data = data >> 1; 00283 data.3 = test_pin(ht1632_data_port, ht1632_data_pin); 00284 00285 set_pin (ht1632_rd_port, ht1632_rd_pin); 00286 00287 } 00288 00289 make_output(ht1632_data_port, ht1632_data_pin); 00290 00291 // now we have the data, we need to change the bit 00292 if (colour) { 00293 set_bit(data, bit_in_mem_addr); 00294 } else { 00295 clear_bit(data, bit_in_mem_addr); 00296 } 00297 00298 // Now write it back out again 00299 00300 // write data, bits 0 -> 3 (different from mem addr format) 00301 for(count = 0 ; count < 4 ; count++) { 00302 //change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(data, 0)); 00303 if (test_bit(data, 0)) { 00304 set_pin(ht1632_data_port, ht1632_data_pin); 00305 } else { 00306 clear_pin(ht1632_data_port, ht1632_data_pin); 00307 } 00308 00309 // pulse wr 00310 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00311 set_pin (ht1632_wr_port, ht1632_wr_pin); 00312 // shift data along 00313 data = data >> 1; 00314 } 00315 00316 00317 // reset CS 00318 // don't think this is necessary 00319 // set_pin(ht1632_cs1_port, ht1632_cs1_pin); 00320 // clear_pin(ht1632_cs1_port, ht1632_cs1_pin); 00321 set_pin (ht1632_cs1_port, ht1632_cs1_pin); 00322 00323 00324 }
void ht1632_setup_io | ( | ) |
00041 { 00042 00043 make_output(ht1632_cs1_port, ht1632_cs1_pin); 00044 00045 #if ht1632_displays > 1 00046 make_output(ht1632_cs2_port, ht1632_cs2_pin); 00047 #endif 00048 #if ht1632_displays > 2 00049 make_output(ht1632_cs3_port, ht1632_cs3_pin); 00050 #endif 00051 #if ht1632_displays > 3 00052 make_output(ht1632_cs4_port, ht1632_cs4_pin); 00053 #endif 00054 00055 00056 make_output(ht1632_data_port, ht1632_data_pin); 00057 make_output(ht1632_wr_port, ht1632_wr_pin); 00058 make_output(ht1632_rd_port, ht1632_rd_pin); 00059 00060 set_pin(ht1632_wr_port, ht1632_wr_pin); 00061 set_pin(ht1632_rd_port, ht1632_rd_pin); 00062 set_pin(ht1632_cs1_port, ht1632_cs1_pin); 00063 #if ht1632_displays > 1 00064 set_pin(ht1632_cs2_port, ht1632_cs2_pin); 00065 #endif 00066 #if ht1632_displays > 2 00067 set_pin(ht1632_cs3_port, ht1632_cs3_pin); 00068 #endif 00069 #if ht1632_displays > 3 00070 set_pin(ht1632_cs4_port, ht1632_cs4_pin); 00071 #endif 00072 00073 }
void ht1632_write | ( | uns8 | mem_addr, | |
uns8 | data | |||
) |
00142 { 00143 00144 uns8 count; 00145 00146 clear_pin(ht1632_cs1_port, ht1632_cs1_pin); 00147 00148 // send WR command 00149 00150 // send 1 00151 set_pin (ht1632_data_port, ht1632_data_pin); 00152 // pulse wr 00153 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00154 set_pin (ht1632_wr_port, ht1632_wr_pin); 00155 00156 // send 0 00157 clear_pin (ht1632_data_port, ht1632_data_pin); 00158 // pulse wr 00159 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00160 set_pin (ht1632_wr_port, ht1632_wr_pin); 00161 00162 // send 1 00163 set_pin (ht1632_data_port, ht1632_data_pin); 00164 // pulse wr 00165 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00166 set_pin (ht1632_wr_port, ht1632_wr_pin); 00167 00168 // write mem addr, bits 6 -> 0 00169 for(count = 0 ; count < 7 ; count++) { 00170 if (test_bit(mem_addr, 6)) { 00171 set_pin(ht1632_data_port, ht1632_data_pin); 00172 } else { 00173 clear_pin(ht1632_data_port, ht1632_data_pin); 00174 } 00175 00176 //change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6)); 00177 // pulse wr 00178 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00179 set_pin (ht1632_wr_port, ht1632_wr_pin); 00180 // shift mem addr along 00181 mem_addr = mem_addr << 1; 00182 } 00183 00184 // write data, bits 0 -> 3 (different from mem addr format) 00185 for(count = 0 ; count < 4 ; count++) { 00186 change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(data, 0)); 00187 // pulse wr 00188 clear_pin(ht1632_wr_port, ht1632_wr_pin); 00189 set_pin (ht1632_wr_port, ht1632_wr_pin); 00190 // shift mem addr along 00191 data = data >> 1; 00192 } 00193 // reset CS 00194 00195 // set_pin(ht1632_cs1_port, ht1632_cs1_pin); 00196 // delay_ms(1); 00197 // clear_pin(ht1632_cs1_port, ht1632_cs1_pin); 00198 set_pin(ht1632_cs1_port, ht1632_cs1_pin); 00199 00200 00201 }