David Buck
/
voltmeter
LCD_setup.cpp@0:d322a5241da8, 2009-12-16 (annotated)
- Committer:
- Kaikestu
- Date:
- Wed Dec 16 12:04:23 2009 +0000
- Revision:
- 0:d322a5241da8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kaikestu | 0:d322a5241da8 | 1 | // LCD_setup.cpp |
Kaikestu | 0:d322a5241da8 | 2 | |
Kaikestu | 0:d322a5241da8 | 3 | #include "header.h" |
Kaikestu | 0:d322a5241da8 | 4 | /***************************************************** |
Kaikestu | 0:d322a5241da8 | 5 | subroutines |
Kaikestu | 0:d322a5241da8 | 6 | *****************************************************/ |
Kaikestu | 0:d322a5241da8 | 7 | /****initialise LCD function ****/ |
Kaikestu | 0:d322a5241da8 | 8 | void LCD_init(void){ |
Kaikestu | 0:d322a5241da8 | 9 | delay_l(); |
Kaikestu | 0:d322a5241da8 | 10 | FIO2DIR0=0xFF; /* set port 2 byte 0 (ctrl) to output */ |
Kaikestu | 0:d322a5241da8 | 11 | FIO2PIN0=0x00; //clear Port 2 byte 0 |
Kaikestu | 0:d322a5241da8 | 12 | //FIO2PIN bit0=R/W (read/write) |
Kaikestu | 0:d322a5241da8 | 13 | //FIO2PIN bit1=RS (register select) |
Kaikestu | 0:d322a5241da8 | 14 | //FIO2PIN bit2=E (enable) |
Kaikestu | 0:d322a5241da8 | 15 | //all initialised low |
Kaikestu | 0:d322a5241da8 | 16 | |
Kaikestu | 0:d322a5241da8 | 17 | // set Port 0 and 1 to operate as fast registers |
Kaikestu | 0:d322a5241da8 | 18 | SCS |= 0x00000001; // by setting the GPIOM bit of the SCS register |
Kaikestu | 0:d322a5241da8 | 19 | FIO0DIR2=0xFF; // set port 0 byte 2 (data) to output |
Kaikestu | 0:d322a5241da8 | 20 | FIO0PIN2=0x00; // clear Port 0 byte 2 |
Kaikestu | 0:d322a5241da8 | 21 | |
Kaikestu | 0:d322a5241da8 | 22 | /* RS already initialised to 'instruction' (low) */ |
Kaikestu | 0:d322a5241da8 | 23 | |
Kaikestu | 0:d322a5241da8 | 24 | /**** Function set*/ |
Kaikestu | 0:d322a5241da8 | 25 | FIO0PIN2=0x38; /* 2-line mode, 7 dot characters */ |
Kaikestu | 0:d322a5241da8 | 26 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 27 | |
Kaikestu | 0:d322a5241da8 | 28 | /**** Display on/off*/ |
Kaikestu | 0:d322a5241da8 | 29 | FIO0PIN2=0x0C; /* display on, cursor off, blink off */ |
Kaikestu | 0:d322a5241da8 | 30 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 31 | |
Kaikestu | 0:d322a5241da8 | 32 | /**** Clear display */ |
Kaikestu | 0:d322a5241da8 | 33 | FIO0PIN2=0x01; /* clear */ |
Kaikestu | 0:d322a5241da8 | 34 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 35 | |
Kaikestu | 0:d322a5241da8 | 36 | /**** Set entry mode */ |
Kaikestu | 0:d322a5241da8 | 37 | FIO0PIN2=0x06; /* increment cursor, shift off */ |
Kaikestu | 0:d322a5241da8 | 38 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 39 | |
Kaikestu | 0:d322a5241da8 | 40 | } |
Kaikestu | 0:d322a5241da8 | 41 | |
Kaikestu | 0:d322a5241da8 | 42 | |
Kaikestu | 0:d322a5241da8 | 43 | /**** LCD Display 'Voltmeter' */ |
Kaikestu | 0:d322a5241da8 | 44 | void LCD_displayV(){ |
Kaikestu | 0:d322a5241da8 | 45 | FIO2CLR0=0x02; /* set RS to 'control' */ |
Kaikestu | 0:d322a5241da8 | 46 | FIO0PIN2=0x01; /* clear display*/ |
Kaikestu | 0:d322a5241da8 | 47 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 48 | FIO2SET0=0x02; /* set RS to 'data' */ |
Kaikestu | 0:d322a5241da8 | 49 | |
Kaikestu | 0:d322a5241da8 | 50 | FIO0PIN2=_sp; // process and display character |
Kaikestu | 0:d322a5241da8 | 51 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 52 | FIO0PIN2=_sp; |
Kaikestu | 0:d322a5241da8 | 53 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 54 | FIO0PIN2=_sp; |
Kaikestu | 0:d322a5241da8 | 55 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 56 | FIO0PIN2=_V; |
Kaikestu | 0:d322a5241da8 | 57 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 58 | FIO0PIN2=_O; |
Kaikestu | 0:d322a5241da8 | 59 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 60 | FIO0PIN2=_L; |
Kaikestu | 0:d322a5241da8 | 61 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 62 | FIO0PIN2=_T; |
Kaikestu | 0:d322a5241da8 | 63 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 64 | FIO0PIN2=_M; |
Kaikestu | 0:d322a5241da8 | 65 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 66 | FIO0PIN2=_E; |
Kaikestu | 0:d322a5241da8 | 67 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 68 | FIO0PIN2=_T; |
Kaikestu | 0:d322a5241da8 | 69 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 70 | FIO0PIN2=_E; |
Kaikestu | 0:d322a5241da8 | 71 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 72 | FIO0PIN2=_R; |
Kaikestu | 0:d322a5241da8 | 73 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 74 | |
Kaikestu | 0:d322a5241da8 | 75 | /* start of line 2 */ |
Kaikestu | 0:d322a5241da8 | 76 | FIO2CLR0=0x02; /* set RS to 'instruction' */ |
Kaikestu | 0:d322a5241da8 | 77 | FIO0PIN2=0xC6; /* set address to line 2 */ |
Kaikestu | 0:d322a5241da8 | 78 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 79 | FIO2SET0=0x02; /* set RS to 'data' */ |
Kaikestu | 0:d322a5241da8 | 80 | |
Kaikestu | 0:d322a5241da8 | 81 | FIO0PIN2=_0; |
Kaikestu | 0:d322a5241da8 | 82 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 83 | FIO0PIN2=0x2e; |
Kaikestu | 0:d322a5241da8 | 84 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 85 | FIO0PIN2=_0; |
Kaikestu | 0:d322a5241da8 | 86 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 87 | FIO0PIN2=_V; |
Kaikestu | 0:d322a5241da8 | 88 | toggle_enable(); |
Kaikestu | 0:d322a5241da8 | 89 | } |
Kaikestu | 0:d322a5241da8 | 90 | |
Kaikestu | 0:d322a5241da8 | 91 | /*** toggle_enable */ |
Kaikestu | 0:d322a5241da8 | 92 | void toggle_enable(void){ |
Kaikestu | 0:d322a5241da8 | 93 | FIO2SET0=0x04; // Toggle enable flag on */ |
Kaikestu | 0:d322a5241da8 | 94 | delay_s(); |
Kaikestu | 0:d322a5241da8 | 95 | FIO2CLR0=0x04; /* Toggle enable flag off */ |
Kaikestu | 0:d322a5241da8 | 96 | delay_s(); |
Kaikestu | 0:d322a5241da8 | 97 | } |
Kaikestu | 0:d322a5241da8 | 98 | |
Kaikestu | 0:d322a5241da8 | 99 | /************************************************************************** |
Kaikestu | 0:d322a5241da8 | 100 | * DEM16217 LCD connected to mbed as follows: |
Kaikestu | 0:d322a5241da8 | 101 | ************************************************************************** |
Kaikestu | 0:d322a5241da8 | 102 | RW = Read/Write = LCD pin05 = mbed pin16 = LPC pin75 = GPIO P2.0 (Port2,byte0,bit0) |
Kaikestu | 0:d322a5241da8 | 103 | RS = RegisterSelect = LCD pin04 = mbed pin15 = LPC pin74 = GPIO P2.1 (0,1) |
Kaikestu | 0:d322a5241da8 | 104 | E = Enable = LCD pin06 = mbed pin14 = LPC pin73 = GPIO P2.2 (0,2) |
Kaikestu | 0:d322a5241da8 | 105 | DB0 = Data Bit 0 = LCD pin07 = mbed pin10 = LPC pin63 = GPIO P0.16 (Port0,byte2,bit0) |
Kaikestu | 0:d322a5241da8 | 106 | DB1 = Data Bit 1 = LCD pin08 = mbed pin08 = LPC pin61 = GPIO P0.17 (2,1) |
Kaikestu | 0:d322a5241da8 | 107 | DB2 = Data Bit 2 = LCD pin09 = mbed pin07 = LPC pin60 = GPIO P0.18 (2,2) |
Kaikestu | 0:d322a5241da8 | 108 | DB3 = Data Bit 3 = LCD pin10 = mbed pin06 = LPC pin59 = GPIO P0.19 (2,3) |
Kaikestu | 0:d322a5241da8 | 109 | DB4 = Data Bit 4 = LCD pin11 = mbed pin05 = LPC pin58 = GPIO P0.20 (2,4) |
Kaikestu | 0:d322a5241da8 | 110 | DB5 = Data Bit 5 = LCD pin12 = mbed pin04 = LPC pin57 = GPIO P0.21 (2,5) |
Kaikestu | 0:d322a5241da8 | 111 | DB6 = Data Bit 6 = LCD pin13 = mbed pin03 = LPC pin56 = GPIO P0.22 (2,6) |
Kaikestu | 0:d322a5241da8 | 112 | DB7 = Data Bit 7 = LCD pin14 = mbed pin36 = LPC pin09 = GPIO P0.23 (2,7) |
Kaikestu | 0:d322a5241da8 | 113 | **************************************************************************/ |