Sistema de supervision y alarma para deposito de comida de animales

Committer:
ciror00
Date:
Fri May 14 17:27:28 2021 +0000
Revision:
0:5e7248732177
Trabajo final de la materia Introduccion a los Sistemas Embebidos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ciror00 0:5e7248732177 1 //=====[Libraries]=============================================================
ciror00 0:5e7248732177 2
ciror00 0:5e7248732177 3 #include "mbed.h"
ciror00 0:5e7248732177 4 #include "arm_book_lib.h"
ciror00 0:5e7248732177 5 #include "display.h"
ciror00 0:5e7248732177 6
ciror00 0:5e7248732177 7 //=====[Declaration of private defines]========================================
ciror00 0:5e7248732177 8
ciror00 0:5e7248732177 9 #define DISPLAY_IR_CLEAR_DISPLAY 0b00000001
ciror00 0:5e7248732177 10 #define DISPLAY_IR_ENTRY_MODE_SET 0b00000100
ciror00 0:5e7248732177 11 #define DISPLAY_IR_DISPLAY_CONTROL 0b00001000
ciror00 0:5e7248732177 12 #define DISPLAY_IR_FUNCTION_SET 0b00100000
ciror00 0:5e7248732177 13 #define DISPLAY_IR_SET_DDRAM_ADDR 0b10000000
ciror00 0:5e7248732177 14
ciror00 0:5e7248732177 15 #define DISPLAY_IR_ENTRY_MODE_SET_INCREMENT 0b00000010
ciror00 0:5e7248732177 16 #define DISPLAY_IR_ENTRY_MODE_SET_DECREMENT 0b00000000
ciror00 0:5e7248732177 17 #define DISPLAY_IR_ENTRY_MODE_SET_SHIFT 0b00000001
ciror00 0:5e7248732177 18 #define DISPLAY_IR_ENTRY_MODE_SET_NO_SHIFT 0b00000000
ciror00 0:5e7248732177 19
ciror00 0:5e7248732177 20 #define DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_ON 0b00000100
ciror00 0:5e7248732177 21 #define DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_OFF 0b00000000
ciror00 0:5e7248732177 22 #define DISPLAY_IR_DISPLAY_CONTROL_CURSOR_ON 0b00000010
ciror00 0:5e7248732177 23 #define DISPLAY_IR_DISPLAY_CONTROL_CURSOR_OFF 0b00000000
ciror00 0:5e7248732177 24 #define DISPLAY_IR_DISPLAY_CONTROL_BLINK_ON 0b00000001
ciror00 0:5e7248732177 25 #define DISPLAY_IR_DISPLAY_CONTROL_BLINK_OFF 0b00000000
ciror00 0:5e7248732177 26
ciror00 0:5e7248732177 27 #define DISPLAY_IR_FUNCTION_SET_8BITS 0b00010000
ciror00 0:5e7248732177 28 #define DISPLAY_IR_FUNCTION_SET_4BITS 0b00000000
ciror00 0:5e7248732177 29 #define DISPLAY_IR_FUNCTION_SET_2LINES 0b00001000
ciror00 0:5e7248732177 30 #define DISPLAY_IR_FUNCTION_SET_1LINE 0b00000000
ciror00 0:5e7248732177 31 #define DISPLAY_IR_FUNCTION_SET_5x10DOTS 0b00000100
ciror00 0:5e7248732177 32 #define DISPLAY_IR_FUNCTION_SET_5x8DOTS 0b00000000
ciror00 0:5e7248732177 33
ciror00 0:5e7248732177 34 #define DISPLAY_20x4_LINE1_FIRST_CHARACTER_ADDRESS 0
ciror00 0:5e7248732177 35 #define DISPLAY_20x4_LINE2_FIRST_CHARACTER_ADDRESS 64
ciror00 0:5e7248732177 36 #define DISPLAY_20x4_LINE3_FIRST_CHARACTER_ADDRESS 20
ciror00 0:5e7248732177 37 #define DISPLAY_20x4_LINE4_FIRST_CHARACTER_ADDRESS 84
ciror00 0:5e7248732177 38
ciror00 0:5e7248732177 39 #define DISPLAY_RS_INSTRUCTION 0
ciror00 0:5e7248732177 40 #define DISPLAY_RS_DATA 1
ciror00 0:5e7248732177 41
ciror00 0:5e7248732177 42 #define DISPLAY_RW_WRITE 0
ciror00 0:5e7248732177 43 #define DISPLAY_RW_READ 1
ciror00 0:5e7248732177 44
ciror00 0:5e7248732177 45 #define DISPLAY_PIN_RS 4
ciror00 0:5e7248732177 46 #define DISPLAY_PIN_RW 5
ciror00 0:5e7248732177 47 #define DISPLAY_PIN_EN 6
ciror00 0:5e7248732177 48 #define DISPLAY_PIN_D0 7
ciror00 0:5e7248732177 49 #define DISPLAY_PIN_D1 8
ciror00 0:5e7248732177 50 #define DISPLAY_PIN_D2 9
ciror00 0:5e7248732177 51 #define DISPLAY_PIN_D3 10
ciror00 0:5e7248732177 52 #define DISPLAY_PIN_D4 11
ciror00 0:5e7248732177 53 #define DISPLAY_PIN_D5 12
ciror00 0:5e7248732177 54 #define DISPLAY_PIN_D6 13
ciror00 0:5e7248732177 55 #define DISPLAY_PIN_D7 14
ciror00 0:5e7248732177 56
ciror00 0:5e7248732177 57 #define DISPLAY_PIN_A_PCF8574 3
ciror00 0:5e7248732177 58
ciror00 0:5e7248732177 59 #define I2C1_SDA PB_9
ciror00 0:5e7248732177 60 #define I2C1_SCL PB_8
ciror00 0:5e7248732177 61
ciror00 0:5e7248732177 62 #define PCF8574_I2C_BUS_8BIT_WRITE_ADDRESS 78
ciror00 0:5e7248732177 63
ciror00 0:5e7248732177 64 //=====[Declaration of private data types]=====================================
ciror00 0:5e7248732177 65
ciror00 0:5e7248732177 66 typedef struct{
ciror00 0:5e7248732177 67 int address;
ciror00 0:5e7248732177 68 char data;
ciror00 0:5e7248732177 69 bool displayPin_RS;
ciror00 0:5e7248732177 70 bool displayPin_RW;
ciror00 0:5e7248732177 71 bool displayPin_EN;
ciror00 0:5e7248732177 72 bool displayPin_A;
ciror00 0:5e7248732177 73 bool displayPin_D4;
ciror00 0:5e7248732177 74 bool displayPin_D5;
ciror00 0:5e7248732177 75 bool displayPin_D6;
ciror00 0:5e7248732177 76 bool displayPin_D7;
ciror00 0:5e7248732177 77 } pcf8574_t;
ciror00 0:5e7248732177 78
ciror00 0:5e7248732177 79 //=====[Declaration and initialization of public global objects]===============
ciror00 0:5e7248732177 80
ciror00 0:5e7248732177 81 DigitalOut displayD0( D0 );
ciror00 0:5e7248732177 82 DigitalOut displayD1( D1 );
ciror00 0:5e7248732177 83 DigitalOut displayD2( D2 );
ciror00 0:5e7248732177 84 DigitalOut displayD3( D3 );
ciror00 0:5e7248732177 85 DigitalOut displayD4( D4 );
ciror00 0:5e7248732177 86 DigitalOut displayD5( D5 );
ciror00 0:5e7248732177 87 DigitalOut displayD6( D6 );
ciror00 0:5e7248732177 88 DigitalOut displayD7( D7 );
ciror00 0:5e7248732177 89 DigitalOut displayRS( D8 );
ciror00 0:5e7248732177 90 DigitalOut displayEN( D9 );
ciror00 0:5e7248732177 91
ciror00 0:5e7248732177 92 I2C I2C_PCF8574( I2C1_SDA, I2C1_SCL );
ciror00 0:5e7248732177 93
ciror00 0:5e7248732177 94 //=====[Declaration of external public global variables]=======================
ciror00 0:5e7248732177 95
ciror00 0:5e7248732177 96 //=====[Declaration and initialization of public global variables]=============
ciror00 0:5e7248732177 97
ciror00 0:5e7248732177 98 //=====[Declaration and initialization of private global variables]============
ciror00 0:5e7248732177 99
ciror00 0:5e7248732177 100 static display_t display;
ciror00 0:5e7248732177 101 static pcf8574_t pcf8574;
ciror00 0:5e7248732177 102 static bool initial8BitCommunicationIsCompleted;
ciror00 0:5e7248732177 103
ciror00 0:5e7248732177 104 //=====[Declarations (prototypes) of private functions]========================
ciror00 0:5e7248732177 105
ciror00 0:5e7248732177 106 static void displayPinWrite( uint8_t pinName, int value );
ciror00 0:5e7248732177 107 static void displayDataBusWrite( uint8_t dataByte );
ciror00 0:5e7248732177 108 static void displayCodeWrite( bool type, uint8_t dataBus );
ciror00 0:5e7248732177 109
ciror00 0:5e7248732177 110 //=====[Implementations of public functions]===================================
ciror00 0:5e7248732177 111
ciror00 0:5e7248732177 112 void displayInit( displayConnection_t connection )
ciror00 0:5e7248732177 113 {
ciror00 0:5e7248732177 114 display.connection = connection;
ciror00 0:5e7248732177 115
ciror00 0:5e7248732177 116 if( display.connection == DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER) {
ciror00 0:5e7248732177 117 pcf8574.address = PCF8574_I2C_BUS_8BIT_WRITE_ADDRESS;
ciror00 0:5e7248732177 118 pcf8574.data = 0b00000000;
ciror00 0:5e7248732177 119 I2C_PCF8574.frequency(100000);
ciror00 0:5e7248732177 120 displayPinWrite( DISPLAY_PIN_A_PCF8574, ON );
ciror00 0:5e7248732177 121 }
ciror00 0:5e7248732177 122
ciror00 0:5e7248732177 123 initial8BitCommunicationIsCompleted = FALSE;
ciror00 0:5e7248732177 124
ciror00 0:5e7248732177 125 delay( 50 );
ciror00 0:5e7248732177 126
ciror00 0:5e7248732177 127 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 128 DISPLAY_IR_FUNCTION_SET |
ciror00 0:5e7248732177 129 DISPLAY_IR_FUNCTION_SET_8BITS );
ciror00 0:5e7248732177 130 delay( 5 );
ciror00 0:5e7248732177 131
ciror00 0:5e7248732177 132 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 133 DISPLAY_IR_FUNCTION_SET |
ciror00 0:5e7248732177 134 DISPLAY_IR_FUNCTION_SET_8BITS );
ciror00 0:5e7248732177 135 delay( 1 );
ciror00 0:5e7248732177 136
ciror00 0:5e7248732177 137 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 138 DISPLAY_IR_FUNCTION_SET |
ciror00 0:5e7248732177 139 DISPLAY_IR_FUNCTION_SET_8BITS );
ciror00 0:5e7248732177 140 delay( 1 );
ciror00 0:5e7248732177 141
ciror00 0:5e7248732177 142 switch( display.connection ) {
ciror00 0:5e7248732177 143 case DISPLAY_CONNECTION_GPIO_8BITS:
ciror00 0:5e7248732177 144 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 145 DISPLAY_IR_FUNCTION_SET |
ciror00 0:5e7248732177 146 DISPLAY_IR_FUNCTION_SET_8BITS |
ciror00 0:5e7248732177 147 DISPLAY_IR_FUNCTION_SET_2LINES |
ciror00 0:5e7248732177 148 DISPLAY_IR_FUNCTION_SET_5x8DOTS );
ciror00 0:5e7248732177 149 delay( 1 );
ciror00 0:5e7248732177 150 break;
ciror00 0:5e7248732177 151
ciror00 0:5e7248732177 152 case DISPLAY_CONNECTION_GPIO_4BITS:
ciror00 0:5e7248732177 153 case DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER:
ciror00 0:5e7248732177 154 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 155 DISPLAY_IR_FUNCTION_SET |
ciror00 0:5e7248732177 156 DISPLAY_IR_FUNCTION_SET_4BITS );
ciror00 0:5e7248732177 157 delay( 1 );
ciror00 0:5e7248732177 158
ciror00 0:5e7248732177 159 initial8BitCommunicationIsCompleted = TRUE;
ciror00 0:5e7248732177 160
ciror00 0:5e7248732177 161 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 162 DISPLAY_IR_FUNCTION_SET |
ciror00 0:5e7248732177 163 DISPLAY_IR_FUNCTION_SET_4BITS |
ciror00 0:5e7248732177 164 DISPLAY_IR_FUNCTION_SET_2LINES |
ciror00 0:5e7248732177 165 DISPLAY_IR_FUNCTION_SET_5x8DOTS );
ciror00 0:5e7248732177 166 delay( 1 );
ciror00 0:5e7248732177 167 break;
ciror00 0:5e7248732177 168 }
ciror00 0:5e7248732177 169
ciror00 0:5e7248732177 170 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 171 DISPLAY_IR_DISPLAY_CONTROL |
ciror00 0:5e7248732177 172 DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_OFF |
ciror00 0:5e7248732177 173 DISPLAY_IR_DISPLAY_CONTROL_CURSOR_OFF |
ciror00 0:5e7248732177 174 DISPLAY_IR_DISPLAY_CONTROL_BLINK_OFF );
ciror00 0:5e7248732177 175 delay( 1 );
ciror00 0:5e7248732177 176
ciror00 0:5e7248732177 177 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 178 DISPLAY_IR_CLEAR_DISPLAY );
ciror00 0:5e7248732177 179 delay( 1 );
ciror00 0:5e7248732177 180
ciror00 0:5e7248732177 181 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 182 DISPLAY_IR_ENTRY_MODE_SET |
ciror00 0:5e7248732177 183 DISPLAY_IR_ENTRY_MODE_SET_INCREMENT |
ciror00 0:5e7248732177 184 DISPLAY_IR_ENTRY_MODE_SET_NO_SHIFT );
ciror00 0:5e7248732177 185 delay( 1 );
ciror00 0:5e7248732177 186
ciror00 0:5e7248732177 187 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 188 DISPLAY_IR_DISPLAY_CONTROL |
ciror00 0:5e7248732177 189 DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_ON |
ciror00 0:5e7248732177 190 DISPLAY_IR_DISPLAY_CONTROL_CURSOR_OFF |
ciror00 0:5e7248732177 191 DISPLAY_IR_DISPLAY_CONTROL_BLINK_OFF );
ciror00 0:5e7248732177 192 delay( 1 );
ciror00 0:5e7248732177 193 }
ciror00 0:5e7248732177 194
ciror00 0:5e7248732177 195 void displayCharPositionWrite( uint8_t charPositionX, uint8_t charPositionY )
ciror00 0:5e7248732177 196 {
ciror00 0:5e7248732177 197 switch( charPositionY ) {
ciror00 0:5e7248732177 198 case 0:
ciror00 0:5e7248732177 199 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 200 DISPLAY_IR_SET_DDRAM_ADDR |
ciror00 0:5e7248732177 201 ( DISPLAY_20x4_LINE1_FIRST_CHARACTER_ADDRESS +
ciror00 0:5e7248732177 202 charPositionX ) );
ciror00 0:5e7248732177 203 delay( 1 );
ciror00 0:5e7248732177 204 break;
ciror00 0:5e7248732177 205
ciror00 0:5e7248732177 206 case 1:
ciror00 0:5e7248732177 207 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 208 DISPLAY_IR_SET_DDRAM_ADDR |
ciror00 0:5e7248732177 209 ( DISPLAY_20x4_LINE2_FIRST_CHARACTER_ADDRESS +
ciror00 0:5e7248732177 210 charPositionX ) );
ciror00 0:5e7248732177 211 delay( 1 );
ciror00 0:5e7248732177 212 break;
ciror00 0:5e7248732177 213
ciror00 0:5e7248732177 214 case 2:
ciror00 0:5e7248732177 215 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 216 DISPLAY_IR_SET_DDRAM_ADDR |
ciror00 0:5e7248732177 217 ( DISPLAY_20x4_LINE3_FIRST_CHARACTER_ADDRESS +
ciror00 0:5e7248732177 218 charPositionX ) );
ciror00 0:5e7248732177 219 delay( 1 );
ciror00 0:5e7248732177 220 break;
ciror00 0:5e7248732177 221
ciror00 0:5e7248732177 222 case 3:
ciror00 0:5e7248732177 223 displayCodeWrite( DISPLAY_RS_INSTRUCTION,
ciror00 0:5e7248732177 224 DISPLAY_IR_SET_DDRAM_ADDR |
ciror00 0:5e7248732177 225 ( DISPLAY_20x4_LINE4_FIRST_CHARACTER_ADDRESS +
ciror00 0:5e7248732177 226 charPositionX ) );
ciror00 0:5e7248732177 227 delay( 1 );
ciror00 0:5e7248732177 228 break;
ciror00 0:5e7248732177 229 }
ciror00 0:5e7248732177 230 }
ciror00 0:5e7248732177 231
ciror00 0:5e7248732177 232 void displayStringWrite( char const * str )
ciror00 0:5e7248732177 233 {
ciror00 0:5e7248732177 234 while (*str) {
ciror00 0:5e7248732177 235 displayCodeWrite(DISPLAY_RS_DATA, *str++);
ciror00 0:5e7248732177 236 }
ciror00 0:5e7248732177 237 }
ciror00 0:5e7248732177 238
ciror00 0:5e7248732177 239 //=====[Implementations of private functions]==================================
ciror00 0:5e7248732177 240
ciror00 0:5e7248732177 241 static void displayCodeWrite( bool type, uint8_t dataBus )
ciror00 0:5e7248732177 242 {
ciror00 0:5e7248732177 243 if ( type == DISPLAY_RS_INSTRUCTION )
ciror00 0:5e7248732177 244 displayPinWrite( DISPLAY_PIN_RS, DISPLAY_RS_INSTRUCTION);
ciror00 0:5e7248732177 245 else
ciror00 0:5e7248732177 246 displayPinWrite( DISPLAY_PIN_RS, DISPLAY_RS_DATA);
ciror00 0:5e7248732177 247 displayPinWrite( DISPLAY_PIN_RW, DISPLAY_RW_WRITE );
ciror00 0:5e7248732177 248 displayDataBusWrite( dataBus );
ciror00 0:5e7248732177 249 }
ciror00 0:5e7248732177 250
ciror00 0:5e7248732177 251 static void displayPinWrite( uint8_t pinName, int value )
ciror00 0:5e7248732177 252 {
ciror00 0:5e7248732177 253 switch( display.connection ) {
ciror00 0:5e7248732177 254 case DISPLAY_CONNECTION_GPIO_8BITS:
ciror00 0:5e7248732177 255 switch( pinName ) {
ciror00 0:5e7248732177 256 case DISPLAY_PIN_D0: displayD0 = value; break;
ciror00 0:5e7248732177 257 case DISPLAY_PIN_D1: displayD1 = value; break;
ciror00 0:5e7248732177 258 case DISPLAY_PIN_D2: displayD2 = value; break;
ciror00 0:5e7248732177 259 case DISPLAY_PIN_D3: displayD3 = value; break;
ciror00 0:5e7248732177 260 case DISPLAY_PIN_D4: displayD4 = value; break;
ciror00 0:5e7248732177 261 case DISPLAY_PIN_D5: displayD5 = value; break;
ciror00 0:5e7248732177 262 case DISPLAY_PIN_D6: displayD6 = value; break;
ciror00 0:5e7248732177 263 case DISPLAY_PIN_D7: displayD7 = value; break;
ciror00 0:5e7248732177 264 case DISPLAY_PIN_RS: displayRS = value; break;
ciror00 0:5e7248732177 265 case DISPLAY_PIN_EN: displayEN = value; break;
ciror00 0:5e7248732177 266 case DISPLAY_PIN_RW: break;
ciror00 0:5e7248732177 267 default: break;
ciror00 0:5e7248732177 268 }
ciror00 0:5e7248732177 269 case DISPLAY_CONNECTION_GPIO_4BITS:
ciror00 0:5e7248732177 270 switch( pinName ) {
ciror00 0:5e7248732177 271 case DISPLAY_PIN_D4: displayD4 = value; break;
ciror00 0:5e7248732177 272 case DISPLAY_PIN_D5: displayD5 = value; break;
ciror00 0:5e7248732177 273 case DISPLAY_PIN_D6: displayD6 = value; break;
ciror00 0:5e7248732177 274 case DISPLAY_PIN_D7: displayD7 = value; break;
ciror00 0:5e7248732177 275 case DISPLAY_PIN_RS: displayRS = value; break;
ciror00 0:5e7248732177 276 case DISPLAY_PIN_EN: displayEN = value; break;
ciror00 0:5e7248732177 277 case DISPLAY_PIN_RW: break;
ciror00 0:5e7248732177 278 default: break;
ciror00 0:5e7248732177 279 }
ciror00 0:5e7248732177 280 break;
ciror00 0:5e7248732177 281
ciror00 0:5e7248732177 282 case DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER:
ciror00 0:5e7248732177 283 if ( value ) {
ciror00 0:5e7248732177 284 switch( pinName ) {
ciror00 0:5e7248732177 285 case DISPLAY_PIN_D4: pcf8574.displayPin_D4 = ON; break;
ciror00 0:5e7248732177 286 case DISPLAY_PIN_D5: pcf8574.displayPin_D5 = ON; break;
ciror00 0:5e7248732177 287 case DISPLAY_PIN_D6: pcf8574.displayPin_D6 = ON; break;
ciror00 0:5e7248732177 288 case DISPLAY_PIN_D7: pcf8574.displayPin_D7 = ON; break;
ciror00 0:5e7248732177 289 case DISPLAY_PIN_RS: pcf8574.displayPin_RS = ON; break;
ciror00 0:5e7248732177 290 case DISPLAY_PIN_EN: pcf8574.displayPin_EN = ON; break;
ciror00 0:5e7248732177 291 case DISPLAY_PIN_RW: pcf8574.displayPin_RW = ON; break;
ciror00 0:5e7248732177 292 case DISPLAY_PIN_A_PCF8574: pcf8574.displayPin_A = ON; break;
ciror00 0:5e7248732177 293 default: break;
ciror00 0:5e7248732177 294 }
ciror00 0:5e7248732177 295 }
ciror00 0:5e7248732177 296 else {
ciror00 0:5e7248732177 297 switch( pinName ) {
ciror00 0:5e7248732177 298 case DISPLAY_PIN_D4: pcf8574.displayPin_D4 = OFF; break;
ciror00 0:5e7248732177 299 case DISPLAY_PIN_D5: pcf8574.displayPin_D5 = OFF; break;
ciror00 0:5e7248732177 300 case DISPLAY_PIN_D6: pcf8574.displayPin_D6 = OFF; break;
ciror00 0:5e7248732177 301 case DISPLAY_PIN_D7: pcf8574.displayPin_D7 = OFF; break;
ciror00 0:5e7248732177 302 case DISPLAY_PIN_RS: pcf8574.displayPin_RS = OFF; break;
ciror00 0:5e7248732177 303 case DISPLAY_PIN_EN: pcf8574.displayPin_EN = OFF; break;
ciror00 0:5e7248732177 304 case DISPLAY_PIN_RW: pcf8574.displayPin_RW = OFF; break;
ciror00 0:5e7248732177 305 case DISPLAY_PIN_A_PCF8574: pcf8574.displayPin_A = OFF; break;
ciror00 0:5e7248732177 306 default: break;
ciror00 0:5e7248732177 307 }
ciror00 0:5e7248732177 308 }
ciror00 0:5e7248732177 309 pcf8574.data = 0b00000000;
ciror00 0:5e7248732177 310 if ( pcf8574.displayPin_RS ) pcf8574.data |= 0b00000001;
ciror00 0:5e7248732177 311 if ( pcf8574.displayPin_RW ) pcf8574.data |= 0b00000010;
ciror00 0:5e7248732177 312 if ( pcf8574.displayPin_EN ) pcf8574.data |= 0b00000100;
ciror00 0:5e7248732177 313 if ( pcf8574.displayPin_A ) pcf8574.data |= 0b00001000;
ciror00 0:5e7248732177 314 if ( pcf8574.displayPin_D4 ) pcf8574.data |= 0b00010000;
ciror00 0:5e7248732177 315 if ( pcf8574.displayPin_D5 ) pcf8574.data |= 0b00100000;
ciror00 0:5e7248732177 316 if ( pcf8574.displayPin_D6 ) pcf8574.data |= 0b01000000;
ciror00 0:5e7248732177 317 if ( pcf8574.displayPin_D7 ) pcf8574.data |= 0b10000000;
ciror00 0:5e7248732177 318 I2C_PCF8574.write( pcf8574.address, &pcf8574.data, 1);
ciror00 0:5e7248732177 319 break;
ciror00 0:5e7248732177 320 }
ciror00 0:5e7248732177 321 }
ciror00 0:5e7248732177 322
ciror00 0:5e7248732177 323 static void displayDataBusWrite( uint8_t dataBus )
ciror00 0:5e7248732177 324 {
ciror00 0:5e7248732177 325 displayPinWrite( DISPLAY_PIN_EN, OFF );
ciror00 0:5e7248732177 326 displayPinWrite( DISPLAY_PIN_D7, dataBus & 0b10000000 );
ciror00 0:5e7248732177 327 displayPinWrite( DISPLAY_PIN_D6, dataBus & 0b01000000 );
ciror00 0:5e7248732177 328 displayPinWrite( DISPLAY_PIN_D5, dataBus & 0b00100000 );
ciror00 0:5e7248732177 329 displayPinWrite( DISPLAY_PIN_D4, dataBus & 0b00010000 );
ciror00 0:5e7248732177 330 switch( display.connection ) {
ciror00 0:5e7248732177 331 case DISPLAY_CONNECTION_GPIO_8BITS:
ciror00 0:5e7248732177 332 displayPinWrite( DISPLAY_PIN_D3, dataBus & 0b00001000 );
ciror00 0:5e7248732177 333 displayPinWrite( DISPLAY_PIN_D2, dataBus & 0b00000100 );
ciror00 0:5e7248732177 334 displayPinWrite( DISPLAY_PIN_D1, dataBus & 0b00000010 );
ciror00 0:5e7248732177 335 displayPinWrite( DISPLAY_PIN_D0, dataBus & 0b00000001 );
ciror00 0:5e7248732177 336 break;
ciror00 0:5e7248732177 337
ciror00 0:5e7248732177 338 case DISPLAY_CONNECTION_GPIO_4BITS:
ciror00 0:5e7248732177 339 case DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER:
ciror00 0:5e7248732177 340 if ( initial8BitCommunicationIsCompleted == TRUE) {
ciror00 0:5e7248732177 341 displayPinWrite( DISPLAY_PIN_EN, ON );
ciror00 0:5e7248732177 342 delay( 1 );
ciror00 0:5e7248732177 343 displayPinWrite( DISPLAY_PIN_EN, OFF );
ciror00 0:5e7248732177 344 delay( 1 );
ciror00 0:5e7248732177 345 displayPinWrite( DISPLAY_PIN_D7, dataBus & 0b00001000 );
ciror00 0:5e7248732177 346 displayPinWrite( DISPLAY_PIN_D6, dataBus & 0b00000100 );
ciror00 0:5e7248732177 347 displayPinWrite( DISPLAY_PIN_D5, dataBus & 0b00000010 );
ciror00 0:5e7248732177 348 displayPinWrite( DISPLAY_PIN_D4, dataBus & 0b00000001 );
ciror00 0:5e7248732177 349 }
ciror00 0:5e7248732177 350 break;
ciror00 0:5e7248732177 351
ciror00 0:5e7248732177 352 }
ciror00 0:5e7248732177 353 displayPinWrite( DISPLAY_PIN_EN, ON );
ciror00 0:5e7248732177 354 delay( 1 );
ciror00 0:5e7248732177 355 displayPinWrite( DISPLAY_PIN_EN, OFF );
ciror00 0:5e7248732177 356 delay( 1 );
ciror00 0:5e7248732177 357 }