The example shows a method of formation of a menu with options on an LCD in 4-bit mode. Setting of bit 1 on port F means go to the next option, whereas setting of bit 0 on port F means go to the previous option. The rate of transition to the next/previous option is limited so the maximum of 4 transitions per second is allowed.
' This project is designed to work with PIC P30F6014A. It has been tested ' on dsPICPRO3 development system with 10.0 MHz crystal and 8xPLL. ' It should work with any other crystal. ' Note: the maximum operating frequency for dsPIC is 120MHz. ' With minor adjustments, this example should work with any other dsPIC MCU program MenuTest1 dim menu_index as short menu as String absolute $1880 ' Array[0..4] of String ' Directive absolute specifies ' the starting address in RAM for a variable. main: ADPCFG = $FFFF ' Configure PORTB as digital TRISF = $FFFF ' Configure PORTF as input (menu control) menu_index = 0 ' Init menu_item menu = "First" ' Menu items menu = "Second" menu = "Third" menu = "Fourth" menu = "Fifth" Lcd_Init_DsPicPro3() ' Init LCD in 4-bit mode for dsPICPRO3 board ' Note: GLCD/LCD Setup routines are in the setup library files located in the Uses folder ' These routines will be moved into AutoComplete in the future. Lcd_Cmd(LCD_CURSOR_OFF) Lcd_Cmd(LCD_FIRST_ROW) Lcd_Out(1,1,"Menu :") Lcd_Out(1,8,menu[menu_index]) ' Show menu element on LCD while true ' endless loop if PORTF.1 = 1 then ' Detect logical one on RF1 pin => MENU UP menu_index = menu_index+1 ' Next index in menu if menu_index>4 then menu_index = 0 ' Circular menu end if Lcd_Out(1,8, " ") ' Clear text Lcd_Out(1,8,menu[menu_index]) ' Show menu element on LCD Delay_ms(250) ' No more than 4 changes per sec end if if PORTF.0 = 1 then ' Detect logical one on RF0 pin => MENU DOWN menu_index = menu_index-1 ' Previous index in menu if menu_index<0 then menu_index = 4 ' Circular menu end if Lcd_Out(1,8, " ") ' Clear text Lcd_Out(1,8,menu[menu_index]) ' Show menu element on LCD Delay_ms(250) ' No more than 4 changes per sec end if wend end.