dip204_example.c File Reference


Detailed Description

LCD DIP204 example driver for EVK1100 board.

This file provides a useful example for the LCD DIP204 on SPI interface. Press PB0 to see the full set of available chars on the LCD Press PB1 to decrease the backlight power of the LCD Press PB2 to increase the backlight power of the LCD Use Joystick to see arrows displayed on the LCD Press Joystick to return to the idle screen

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file dip204_example.c.

#include "board.h"
#include "compiler.h"
#include "dip204.h"
#include "intc.h"
#include "gpio.h"
#include "pm.h"
#include "delay.h"
#include "spi.h"
#include <avr32/io.h>

Go to the source code of this file.

Defines

#define GPIO_BACKLIGHT_MINUS   GPIO_PUSH_BUTTON_1
#define GPIO_BACKLIGHT_PLUS   GPIO_PUSH_BUTTON_2
#define GPIO_CHARSET   GPIO_PUSH_BUTTON_0

Functions

void dip204_example_configure_joystick_IT (void)
 function to configure joystick to generate IT upon falling edge
void dip204_example_configure_push_buttons_IT (void)
 function to configure push button to generate IT upon rising edge
static void dip204_example_Joy_int_handler (void)
 The joystick interrupt handler.
static void dip204_example_PB_int_handler (void)
 The Push Buttons interrupt handler.
int main (void)
 main function : do init and loop (poll if configured so)

Variables

unsigned short current_char = 0
unsigned short display


Define Documentation

#define GPIO_BACKLIGHT_MINUS   GPIO_PUSH_BUTTON_1

define the push button to decrease back light power

Definition at line 104 of file dip204_example.c.

Referenced by dip204_example_configure_push_buttons_IT(), and dip204_example_PB_int_handler().

#define GPIO_BACKLIGHT_PLUS   GPIO_PUSH_BUTTON_2

define the push button to increase back light power

Definition at line 107 of file dip204_example.c.

Referenced by dip204_example_configure_push_buttons_IT(), and dip204_example_PB_int_handler().

#define GPIO_CHARSET   GPIO_PUSH_BUTTON_0

define the push button to see available char map on LCD

Definition at line 101 of file dip204_example.c.

Referenced by dip204_example_configure_push_buttons_IT(), and dip204_example_PB_int_handler().


Function Documentation

void dip204_example_configure_joystick_IT ( void   ) 

function to configure joystick to generate IT upon falling edge

Definition at line 246 of file dip204_example.c.

References dip204_example_Joy_int_handler().

Referenced by main().

00247 {
00248   gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_FALLING_EDGE);
00249   gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_FALLING_EDGE);
00250   gpio_enable_pin_interrupt(GPIO_JOYSTICK_RIGHT , GPIO_FALLING_EDGE);
00251   gpio_enable_pin_interrupt(GPIO_JOYSTICK_PUSH , GPIO_FALLING_EDGE);
00252   gpio_enable_pin_interrupt(GPIO_JOYSTICK_LEFT , GPIO_FALLING_EDGE);
00253 
00254   /* Disable all interrupts */
00255   Disable_global_interrupt();
00256   /* register PB0 handler on level 1 */
00257   INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT1);
00258   INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_DOWN/8), AVR32_INTC_INT1);
00259   INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_RIGHT/8), AVR32_INTC_INT1);
00260   INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_LEFT/8), AVR32_INTC_INT1);
00261   INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_PUSH/8), AVR32_INTC_INT1);
00262   /* Enable all interrupts */
00263   Enable_global_interrupt();
00264 }

void dip204_example_configure_push_buttons_IT ( void   ) 

function to configure push button to generate IT upon rising edge

Definition at line 224 of file dip204_example.c.

References dip204_example_PB_int_handler(), GPIO_BACKLIGHT_MINUS, GPIO_BACKLIGHT_PLUS, and GPIO_CHARSET.

Referenced by main().

00225 {
00226   gpio_enable_pin_interrupt(GPIO_CHARSET , GPIO_RISING_EDGE);
00227 
00228   gpio_enable_pin_interrupt(GPIO_BACKLIGHT_PLUS , GPIO_RISING_EDGE);
00229 
00230   gpio_enable_pin_interrupt(GPIO_BACKLIGHT_MINUS , GPIO_RISING_EDGE);
00231 
00232   /* Disable all interrupts */
00233   Disable_global_interrupt();
00234   /* register PB0 handler on level 1 */
00235   INTC_register_interrupt( &dip204_example_PB_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_BACKLIGHT_PLUS/8), AVR32_INTC_INT1);
00236   INTC_register_interrupt( &dip204_example_PB_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_BACKLIGHT_MINUS/8), AVR32_INTC_INT1);
00237   INTC_register_interrupt( &dip204_example_PB_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_CHARSET/8), AVR32_INTC_INT1);
00238   /* Enable all interrupts */
00239   Enable_global_interrupt();
00240 }

static void dip204_example_Joy_int_handler ( void   )  [static]

The joystick interrupt handler.

Definition at line 174 of file dip204_example.c.

References dip204_set_cursor_position(), dip204_write_data(), dip204_write_string(), and display.

Referenced by dip204_example_configure_joystick_IT().

00175 {
00176   if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP))
00177   {
00178     dip204_set_cursor_position(19,1);
00179     dip204_write_data(0xDE);
00180     display = 1;
00181     /* allow new interrupt : clear the IFR flag */
00182     gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
00183   }
00184   if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN))
00185   {
00186     dip204_set_cursor_position(19,3);
00187     dip204_write_data(0xE0);
00188     display = 1;
00189     /* allow new interrupt : clear the IFR flag */
00190     gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
00191   }
00192   if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_LEFT))
00193   {
00194     dip204_set_cursor_position(18,2);
00195     dip204_write_data(0xE1);
00196     display = 1;
00197     /* allow new interrupt : clear the IFR flag */
00198     gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
00199   }
00200   if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT))
00201   {
00202     dip204_set_cursor_position(20,2);
00203     dip204_write_data(0xDF);
00204     display = 1;
00205     /* allow new interrupt : clear the IFR flag */
00206     gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
00207   }
00208   if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_PUSH))
00209   {
00210     dip204_set_cursor_position(19,2);
00211     dip204_write_data(0xBB);
00212     dip204_set_cursor_position(1,4);
00213     dip204_write_string("  AT32UC3A Series   ");
00214     display = 1;
00215     /* allow new interrupt : clear the IFR flag */
00216     gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
00217   }
00218 }

static void dip204_example_PB_int_handler ( void   )  [static]

The Push Buttons interrupt handler.

Definition at line 124 of file dip204_example.c.

References backlight_power_decrease, backlight_power_increase, current_char, dip204_set_backlight(), dip204_set_cursor_position(), dip204_write_data(), dip204_write_string(), GPIO_BACKLIGHT_MINUS, GPIO_BACKLIGHT_PLUS, and GPIO_CHARSET.

Referenced by dip204_example_configure_push_buttons_IT().

00125 {
00126 unsigned short i;
00127 
00128   /* display all available chars */
00129   if (gpio_get_pin_interrupt_flag(GPIO_CHARSET))
00130   {
00131     /* go to first column of 4th line */
00132     dip204_set_cursor_position(1,4);
00133     /* display 20 chars of charmap */
00134     for (i = current_char; i < current_char + 0x10; i++)
00135     {
00136       dip204_write_data(i);
00137     }
00138     dip204_write_string("    ");
00139     /* mark position in charmap */
00140     current_char = i;
00141     /* reset marker */
00142     if (current_char >= 0xFF)
00143     {
00144       current_char = 0x10;
00145     }
00146     /* allow new interrupt : clear the IFR flag */
00147     gpio_clear_pin_interrupt_flag(GPIO_CHARSET);
00148   }
00149   /* increase backlight power */
00150   if (gpio_get_pin_interrupt_flag(GPIO_BACKLIGHT_PLUS))
00151   {
00152     dip204_set_backlight(backlight_power_increase);
00153     /* allow new interrupt : clear the IFR flag */
00154     gpio_clear_pin_interrupt_flag(GPIO_BACKLIGHT_PLUS);
00155   }
00156   /* decrease backlight power */
00157   if (gpio_get_pin_interrupt_flag(GPIO_BACKLIGHT_MINUS))
00158   {
00159     dip204_set_backlight(backlight_power_decrease);
00160     /* allow new interrupt : clear the IFR flag */
00161     gpio_clear_pin_interrupt_flag(GPIO_BACKLIGHT_MINUS);
00162   }
00163 }

int main ( void   ) 

main function : do init and loop (poll if configured so)

Definition at line 269 of file dip204_example.c.

References backlight_PWM, current_char, dip204_example_configure_joystick_IT(), dip204_example_configure_push_buttons_IT(), dip204_hide_cursor(), dip204_init(), dip204_set_cursor_position(), dip204_write_string(), and display.

00270 {
00271   static const gpio_map_t DIP204_SPI_GPIO_MAP =
00272   {
00273     {DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
00274     {DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
00275     {DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
00276     {DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
00277   };
00278 
00279   // Switch the CPU main clock to oscillator 0
00280   pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00281 
00282   // Disable all interrupts.
00283   Disable_global_interrupt();
00284 
00285   // init the interrupts
00286   INTC_init_interrupts();
00287 
00288   // Enable all interrupts.
00289   Enable_global_interrupt();
00290 
00291   // add the spi options driver structure for the LCD DIP204
00292   spi_options_t spiOptions =
00293   {
00294     .reg          = DIP204_SPI_NPCS,
00295     .baudrate     = 1000000,
00296     .bits         = 8,
00297     .spck_delay   = 0,
00298     .trans_delay  = 0,
00299     .stay_act     = 1,
00300     .spi_mode     = 0,
00301     .modfdis      = 1
00302   };
00303 
00304   // Assign I/Os to SPI
00305   gpio_enable_module(DIP204_SPI_GPIO_MAP,
00306                      sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));
00307 
00308   // Initialize as master
00309   spi_initMaster(DIP204_SPI, &spiOptions);
00310 
00311   // Set selection mode: variable_ps, pcs_decode, delay
00312   spi_selectionMode(DIP204_SPI, 0, 0, 0);
00313 
00314   // Enable SPI
00315   spi_enable(DIP204_SPI);
00316 
00317   // setup chip registers
00318   spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);
00319 
00320   // configure local push buttons
00321   dip204_example_configure_push_buttons_IT();
00322 
00323   // configure local joystick
00324   dip204_example_configure_joystick_IT();
00325 
00326   // initialize delay driver
00327   delay_init( FOSC0 );
00328 
00329   // initialize LCD
00330   dip204_init(backlight_PWM, TRUE);
00331 
00332   // reset marker
00333   current_char = 0x10;
00334 
00335   // Display default message.
00336   dip204_set_cursor_position(8,1);
00337   dip204_write_string("ATMEL");
00338   dip204_set_cursor_position(7,2);
00339   dip204_write_string("EVK1100");
00340   dip204_set_cursor_position(6,3);
00341   dip204_write_string("AVR32 UC3");
00342   dip204_set_cursor_position(3,4);
00343   dip204_write_string("AT32UC3A Series");
00344   dip204_hide_cursor();
00345 
00346   /* do a loop */
00347   while (1)
00348   {
00349     if (display)
00350     {
00351       delay_ms(400);  // A delay so that it is humanly possible to see the
00352                       // character(s) before they are cleared.
00353       // Clear line 1 column 19
00354       dip204_set_cursor_position(19,1);
00355       dip204_write_string(" ");
00356       // Clear line 2 from column 18 to column 20.
00357       dip204_set_cursor_position(18,2);
00358       dip204_write_string("   "); // 3 spaces
00359       // Clear line 3 column 19
00360       dip204_set_cursor_position(19,3);
00361       dip204_write_string(" ");
00362       display = 0;
00363     }
00364   }
00365 }


Variable Documentation

unsigned short current_char = 0

current char displayed on the 4th line

Definition at line 113 of file dip204_example.c.

Referenced by dip204_example_PB_int_handler(), and main().

unsigned short display

flag set when joystick display starts to signal main function to clear this display

Definition at line 110 of file dip204_example.c.

Referenced by dip204_example_Joy_int_handler(), and main().


Generated on Fri Feb 19 02:23:30 2010 for AVR32 UC3 - DIP204 LCD Driver by  doxygen 1.5.5