Commits

Anonymous committed 4633f53

4BIT,8Bit - FastIO for data pins

Comments (0)

Files changed (3)

 syntax: glob
 .DS_Store
+delay_x.h

LiquidCrystal.cpp

                          uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
                          uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
 {
-   uint8_t i;
    
    // Initialize the IO pins
    // -----------------------
    _rw_pin = rw;
    _enable_pin = enable;
    
-   _data_pins[0] = d0;
-   _data_pins[1] = d1;
-   _data_pins[2] = d2;
-   _data_pins[3] = d3; 
-   _data_pins[4] = d4;
-   _data_pins[5] = d5;
-   _data_pins[6] = d6;
-   _data_pins[7] = d7;
+   // Initialize data pins for FastIO
+   _data_bits[0] = fio_pinToBit(d0);
+   _data_bits[1] = fio_pinToBit(d1);
+   _data_bits[2] = fio_pinToBit(d2);
+   _data_bits[3] = fio_pinToBit(d3);
+   _data_registers[0] = fio_pinToOutputRegister(d0);
+   _data_registers[1] = fio_pinToOutputRegister(d1);
+   _data_registers[2] = fio_pinToOutputRegister(d2);
+   _data_registers[3] = fio_pinToOutputRegister(d3);
    
-   // Initialize the IO port direction to OUTPUT
-   // ------------------------------------------
-   
-   for ( i = 0; i < 4; i++ )
-   {
-      pinMode ( _data_pins[i], OUTPUT );
+   if(!fourbitmode){
+	   _data_bits[4] = fio_pinToBit(d4);
+	   _data_bits[5] = fio_pinToBit(d5);
+	   _data_bits[6] = fio_pinToBit(d6);
+	   _data_bits[7] = fio_pinToBit(d7);
+	   _data_registers[4] = fio_pinToOutputRegister(d4);
+	   _data_registers[5] = fio_pinToOutputRegister(d5);
+	   _data_registers[6] = fio_pinToOutputRegister(d6);
+	   _data_registers[7] = fio_pinToOutputRegister(d7);
    }
-   
-   // Initialize the rest of the ports if it is an 8bit controlled LCD
-   // ----------------------------------------------------------------
-   
-   if ( !fourbitmode )
-   {
-      for ( i = 4; i < 8; i++ )
-      {
-         pinMode ( _data_pins[i], OUTPUT );
-      }
-   }
+
    pinMode(_rs_pin, OUTPUT);
    
    // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
       // figure 24, pg 46
       
       // we start in 8bit mode, try to set 4 bit mode
-      write4bits(0x03);
+      writeNbits(4,0x03);
       delayMicroseconds(4500); // wait min 4.1ms
       
       // second try
-      write4bits(0x03);
+      writeNbits(4,0x03);
       delayMicroseconds(4500); // wait min 4.1ms
       
       // third go!
-      write4bits(0x03); 
+      writeNbits(4,0x03);
       delayMicroseconds(150);
       
       // finally, set to 4-bit interface
-      write4bits(0x02); 
+      writeNbits(4,0x02);
    } 
    else 
    {
    
    if (_displayfunction & LCD_8BITMODE)
    {
-      write8bits(value); 
+      writeNbits(8, value);
    } 
    else 
    {
-      write4bits ( value >> 4 );
-      write4bits ( value );
+      writeNbits (4, value >> 4);
+      writeNbits (4, value);
    }
    waitUsec ( EXEC_TIME ); // wait for the command to execute by the LCD
 }
 }
 
 //
-// write4bits
-void LiquidCrystal::write4bits(uint8_t value) 
-{
-   for (uint8_t i = 0; i < 4; i++) 
-   {
-      digitalWrite(_data_pins[i], (value >> i) & 0x01);
-   }
-   pulseEnable();
+// writeNbits
+void LiquidCrystal::writeNbits(uint8_t bits, uint8_t value){
+	for(uint8_t i = 0; i < bits; ++i){
+		fio_digitalWrite(_data_registers[i], _data_bits[i], (value >> i) & 0x01);
+	}
 }
-
-//
-// write8bits
-void LiquidCrystal::write8bits(uint8_t value) 
-{
-   for (uint8_t i = 0; i < 8; i++) 
-   {
-      digitalWrite(_data_pins[i], (value >> i) & 0x01);
-   }   
-   pulseEnable();
-}
 
 #include <inttypes.h>
 #include "LCD.h"
+#include "FastIO.h"
 
 
 /*!
    
    /*!
     @method     
-    @abstract   Writes an 8 bit value to the LCD.
-    @discussion Writes 8 bits to the LCD control data lines.
+    @abstract   Writes an 8 or 4 bit value to the LCD.
+    @discussion Writes 8 or 4 bits to the LCD control data lines.
     */
-   void write8bits(uint8_t value);
-   
-   /*!
-    @method     
-    @abstract   Writes an 4 bit value to the LCD.
-    @discussion Writes 4 bits (the least significant) to the LCD control data lines.
-    */   
-   void write4bits(uint8_t value);
+   void writeNbits(uint8_t bits, uint8_t value);
    
    /*!
     @method     
    uint8_t _rs_pin;       // LOW: command.  HIGH: character.
    uint8_t _rw_pin;       // LOW: write to LCD.  HIGH: read from LCD.
    uint8_t _enable_pin;   // activated by a HIGH pulse.
-   uint8_t _data_pins[8]; // Data pins.
+
+   fio_bit _data_bits[8];
+   fio_register _data_registers[8];
 };
 
 #endif