This file defines a useful set of functions for the DIP204 interface on AVR32 devices.
Definition in file dip204.h.
#include "compiler.h"
Go to the source code of this file.
Enumerations | |
enum | backlight_options { backlight_IO = 0, backlight_PWM } |
enum | backlight_power { backlight_power_increase = 0, backlight_power_decrease } |
Functions | |
void | dip204_clear_display (void) |
void | dip204_create_char (char ascii_code, const unsigned char data[8]) |
void | dip204_hide_cursor (void) |
void | dip204_init (backlight_options option, Bool backlight_on) |
void | dip204_printf_string (const char *format,...) |
void | dip204_read_data (unsigned char *data) |
void | dip204_set_backlight (backlight_power power) |
void | dip204_set_cursor_position (unsigned char column, unsigned char line) |
void | dip204_show_cursor (void) |
void | dip204_write_data (unsigned char data) |
void | dip204_write_string (const char *string) |
enum backlight_options |
type for Backlight options : use PWM or IO to drive the backlight
Definition at line 58 of file dip204.h.
00058 { 00059 backlight_IO = 0, 00060 backlight_PWM 00061 }backlight_options;
enum backlight_power |
type for Backlight power : increase or decrease the backlight
Definition at line 66 of file dip204.h.
00066 { 00067 backlight_power_increase = 0, 00068 backlight_power_decrease 00069 }backlight_power;
void dip204_clear_display | ( | void | ) |
Clear the LCD screen (need void delay_ms(unsigned short time_ms) function to perform active wait)
Definition at line 333 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_COMMAND.
00334 { 00335 dip204_select(); 00336 /* Send Command Start Byte */ 00337 dip204_write_byte(DIP204_WRITE_COMMAND); 00338 /* Send Display Clear Command */ 00339 dip204_write_byte(0x01); 00340 /* Wait for command execution */ 00341 delay_ms(4); 00342 dip204_wait_busy(); 00343 dip204_unselect(); 00344 }
void dip204_create_char | ( | char | ascii_code, | |
const unsigned char | data[8] | |||
) |
Create a new ASCII character
ascii_code | Input. ascii code of the new character. Must fit in the range [0; 7]. | |
data | Input. pixel map of the character. It is composed of 5 columns and 8 lines. |
Definition at line 271 of file dip204.c.
References DIP204_CGRAM_BASE_ADDR, dip204_read_byte(), DIP204_READ_COMMAND, dip204_select(), dip204_set_cursor_position(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), DIP204_WRITE_COMMAND, and DIP204_WRITE_DATA.
00272 { 00273 unsigned char i; 00274 unsigned char column, line; 00275 00276 /* select the LCD chip */ 00277 dip204_select(); 00278 00279 /* save cursor position */ 00280 /* Send Read Command Start-Byte */ 00281 dip204_write_byte(DIP204_READ_COMMAND); 00282 /* Read status */ 00283 dip204_read_byte(&i); 00284 /* Extract and save line and column cursor information */ 00285 line = ((i&0x60) >> 5) + 1; 00286 column = (i&0x1F) + 1; 00287 00288 /* Send Command Start Byte */ 00289 dip204_write_byte(DIP204_WRITE_COMMAND); 00290 /* Send CGRAM Address Set command */ 00291 dip204_write_byte(DIP204_CGRAM_BASE_ADDR + ((ascii_code << 3)&0x38)); 00292 /* wait for LCD */ 00293 dip204_wait_busy(); 00294 00295 /* To proceed the 8 lines */ 00296 for(i=0; i<8; i++) 00297 { 00298 /* Send Data Start Byte */ 00299 dip204_write_byte(DIP204_WRITE_DATA); 00300 /* send data */ 00301 dip204_write_byte(data[i] & 0x1F); //data[i]); 00302 /* wait for LCD */ 00303 dip204_wait_busy(); 00304 } 00305 00306 /* unselect chip */ 00307 dip204_unselect(); 00308 00309 /* Reset cursor position */ 00310 dip204_set_cursor_position(column, line); 00311 }
void dip204_hide_cursor | ( | void | ) |
Hide cursor
Definition at line 232 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_COMMAND.
Referenced by main().
00233 { 00234 /* select the LCD chip */ 00235 dip204_select(); 00236 /* Send Command Start Byte */ 00237 dip204_write_byte(DIP204_WRITE_COMMAND); 00238 /* Send "Display On Command: Display On, Cursor On, Blink On" */ 00239 dip204_write_byte(0x0C); 00240 dip204_wait_busy(); 00241 /* unselect chip */ 00242 dip204_unselect(); 00243 }
void dip204_init | ( | backlight_options | option, | |
Bool | backlight_on | |||
) |
Initialize the LCD (need void delay_ms(unsigned short time_ms) function to perform active wait)
option | backlight_IO if no PWM needed, backlight_PWM if PWM needed... | |
backlight_on | Whether to start with backlight on or off. |
Definition at line 103 of file dip204.c.
References backlight_PWM, channel_id, DIP204_PERIOD_MAX, dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), DIP204_WRITE_COMMAND, pwm_channel, and pwm_duty.
Referenced by main().
00104 { 00105 pwm_opt_t pwm_opt; // pwm option config 00106 00107 if (option == backlight_PWM) 00108 { 00109 channel_id = DIP204_PWM_CHANNEL; 00110 gpio_enable_module_pin(AVR32_PWM_6_PIN, AVR32_PWM_6_FUNCTION); 00111 00112 // PWM controller configuration 00113 pwm_opt.diva=0; 00114 pwm_opt.divb=0; 00115 pwm_opt.prea=0; 00116 pwm_opt.preb=0; 00117 00118 pwm_init(&pwm_opt); 00119 pwm_duty = (backlight_on) ? DIP204_PERIOD_MAX - 1 : 1; 00120 pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; // channel mode 00121 pwm_channel.CMR.cpol = PWM_POLARITY_LOW; // channel polarity 00122 pwm_channel.CMR.cpd = PWM_UPDATE_PERIOD; // not used the first time 00123 pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; // channel prescaler 00124 pwm_channel.cdty = pwm_duty; // channel duty cycle, should be < CPRD 00125 pwm_channel.cprd = DIP204_PERIOD_MAX; // channel period 00126 pwm_channel.cupd = 0; // channel update is not used here. 00127 00128 pwm_channel_init(channel_id, &pwm_channel); 00129 // start PWM 00130 pwm_start_channels(1 << channel_id); 00131 } 00132 else 00133 { 00134 if (backlight_on) 00135 { 00136 gpio_clr_gpio_pin(DIP204_BACKLIGHT_PIN); 00137 } 00138 else 00139 { 00140 gpio_set_gpio_pin(DIP204_BACKLIGHT_PIN); 00141 } 00142 } 00143 // delay for power on 00144 delay_ms(20); 00145 // select the LCD chip 00146 dip204_select(); 00147 // Send Command Start Byte 00148 dip204_write_byte(DIP204_WRITE_COMMAND); 00149 // Send "extended Function Set" Command (RE=1) 00150 dip204_write_byte(0x34); 00151 // Wait for command execution 00152 delay_ms(1); 00153 // Send "Enter 4-Line Mode" Command 00154 dip204_write_byte(0x09); 00155 // Wait for command execution 00156 delay_ms(1); 00157 // Send "Function Set" Command (RE=0) 00158 dip204_write_byte(0x30); 00159 // Wait for command execution 00160 delay_ms(1); 00161 // Send "Display On Command: Display On, Cursor On, Blink On" 00162 dip204_write_byte(0x0F); 00163 // Wait for command execution 00164 delay_ms(1); 00165 // Send "Display Clear" Command 00166 dip204_write_byte(0x01); 00167 // Wait for command execution 00168 delay_ms(5); 00169 // Send "Entry Mode Set Command: Increment Mode, Entire Shift off" 00170 dip204_write_byte(0x06); 00171 // Wait for command execution 00172 delay_ms(1); 00173 dip204_wait_busy(); 00174 // unselect chip 00175 dip204_unselect(); 00176 }
void dip204_printf_string | ( | const char * | format, | |
... | ||||
) |
Write a formatted string
format | Input. Formatted null terminated string to display |
Definition at line 367 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_DATA.
00368 { 00369 va_list arg; 00370 char string[21]; 00371 unsigned char i=0; 00372 00373 va_start(arg, format); 00374 i = vsprintf(string, format, arg); 00375 while (i < sizeof(string) - 1) string[i++] = '\0'; 00376 va_end(arg); 00377 dip204_select(); 00378 /* for all chars in string */ 00379 i = 0; 00380 while(string[i]!='\0') 00381 { 00382 /* Send Write Data Start Byte */ 00383 dip204_write_byte(DIP204_WRITE_DATA); 00384 /* Send byte */ 00385 dip204_write_byte(string[i]); 00386 /* go to next char */ 00387 i++; 00388 dip204_wait_busy(); 00389 } 00390 dip204_unselect(); 00391 }
void dip204_read_data | ( | unsigned char * | data | ) |
Read data at current position
data | Output. data read at current position |
Definition at line 258 of file dip204.c.
References dip204_read_byte(), DIP204_READ_DATA, dip204_select(), dip204_unselect(), dip204_wait_busy(), and dip204_write_byte().
00259 { 00260 dip204_select(); 00261 /* Send Read Data Start-Byte */ 00262 dip204_write_byte(DIP204_READ_DATA); 00263 /* read SPI data */ 00264 dip204_read_byte(data); 00265 /* wait for LCD */ 00266 dip204_wait_busy(); 00267 dip204_unselect(); 00268 }
void dip204_set_backlight | ( | backlight_power | power | ) |
Change the backlight power
power | increase or decrease the backlight... |
Definition at line 179 of file dip204.c.
References backlight_power_decrease, backlight_power_increase, channel_id, DIP204_PERIOD_MAX, pwm_channel, and pwm_duty.
Referenced by dip204_example_PB_int_handler().
00180 { 00181 if (channel_id != -1) 00182 { 00183 if (power == backlight_power_decrease) 00184 { 00185 // update channel duty cycle using double buffering to prevent unexpected waveform. 00186 pwm_duty = Max(pwm_duty - (DIP204_PERIOD_MAX / 10), 1); 00187 pwm_channel.CMR.cpd = PWM_UPDATE_DUTY; 00188 // new duty cycle 00189 pwm_channel.cupd = pwm_duty; 00190 // set channel configuration. 00191 pwm_sync_update_channel(channel_id, &pwm_channel); 00192 } 00193 else if (power == backlight_power_increase) 00194 { 00195 // update channel duty cycle using double buffering to prevent unexpected waveform. 00196 pwm_duty = Min(pwm_duty + (DIP204_PERIOD_MAX / 10), DIP204_PERIOD_MAX - 1); 00197 pwm_channel.CMR.cpd = PWM_UPDATE_DUTY; 00198 // new duty cycle 00199 pwm_channel.cupd = pwm_duty; 00200 // set channel configuration. 00201 pwm_sync_update_channel(channel_id, &pwm_channel); 00202 } 00203 } 00204 else 00205 { 00206 if (power == backlight_power_decrease) 00207 { 00208 gpio_set_gpio_pin(DIP204_BACKLIGHT_PIN); 00209 } 00210 else if (power == backlight_power_increase) 00211 { 00212 gpio_clr_gpio_pin(DIP204_BACKLIGHT_PIN); 00213 } 00214 } 00215 }
void dip204_set_cursor_position | ( | unsigned char | column, | |
unsigned char | line | |||
) |
Set cursor to given position
column | Input. Column where to set cursor (from 1 to 20). | |
line | Input. Line where to set cursor (from 1 to 4). |
Definition at line 314 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_COMMAND.
Referenced by dip204_create_char(), dip204_example_Joy_int_handler(), dip204_example_PB_int_handler(), and main().
00315 { 00316 unsigned char address = 0; 00317 00318 dip204_select(); 00319 if ((column <= 20) && (line <= 4)) 00320 { 00321 /* Calculate DDRAM address from line and row values */ 00322 address = ( (line-1) * 32 ) + ( column-1 ) + 128; 00323 } 00324 /* Send Command Start Byte */ 00325 dip204_write_byte(DIP204_WRITE_COMMAND); 00326 /* Send Adress lower Nibble */ 00327 dip204_write_byte(address); 00328 dip204_wait_busy(); 00329 dip204_unselect(); 00330 }
void dip204_show_cursor | ( | void | ) |
Show blinking cursor
Definition at line 218 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_COMMAND.
00219 { 00220 /* select the LCD chip */ 00221 dip204_select(); 00222 /* Send Command Start Byte */ 00223 dip204_write_byte(DIP204_WRITE_COMMAND); 00224 /* Send "Display On Command: Display On, Cursor On, Blink On" */ 00225 dip204_write_byte(0x0F); 00226 dip204_wait_busy(); 00227 /* unselect chip */ 00228 dip204_unselect(); 00229 }
void dip204_write_data | ( | unsigned char | data | ) |
Write a byte at current position
data | Input. data to display |
Definition at line 246 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_DATA.
Referenced by dip204_example_Joy_int_handler(), and dip204_example_PB_int_handler().
00247 { 00248 dip204_select(); 00249 /* Send Write Data Start-Byte */ 00250 dip204_write_byte(DIP204_WRITE_DATA); 00251 /* send data */ 00252 dip204_write_byte(data); 00253 dip204_wait_busy(); 00254 dip204_unselect(); 00255 }
void dip204_write_string | ( | const char * | string | ) |
Write a string
string | Input. null terminated string to display |
Definition at line 347 of file dip204.c.
References dip204_select(), dip204_unselect(), dip204_wait_busy(), dip204_write_byte(), and DIP204_WRITE_DATA.
Referenced by dip204_example_Joy_int_handler(), dip204_example_PB_int_handler(), and main().
00348 { 00349 unsigned char i=0; 00350 00351 dip204_select(); 00352 /* for all chars in string */ 00353 while(string[i]!=0) 00354 { 00355 /* Send Write Data Start Byte */ 00356 dip204_write_byte(DIP204_WRITE_DATA); 00357 /* Send byte */ 00358 dip204_write_byte(string[i]); 00359 /* go to next char */ 00360 i++; 00361 dip204_wait_busy(); 00362 } 00363 dip204_unselect(); 00364 }