Thông báo

Collapse
No announcement yet.

Thảo luận về ARM LPC 2138/2148

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Bác nào đã dùng I2C của LPC chỉ giúp mình với ,mình thử dùng đoạn code sau giao tiếp với PCF8574 nhưng không thấy chạy .Debug đến đoạn
    while((I2C0STAT)!= 0x18){;;} là chương trình dừng ,có lẽ chưa nhận được ack từ slave PCF8574 ????

    void write_PCF8574(unsigned char Addr,unsigned char Data) // Write Output PCF8574A
    {
    I2C0CONCLR = 0x6C; // Reset all I2C Status
    I2C0CONSET |= 0x40; // Enable I2C Interface
    I2C0CONSET |= 0x20; // Send Start Condition

    // Wait I2C Status Return
    while((I2C0STAT)!= 0x08){;;} // Wait Start Condition Complete
    I2C0DAT = Addr; // Send PCF8574A+[Read/Write]
    I2C0CONCLR = 0x28; // Clear Start Bit + Interrupt Flag

    // Wait I2C Status Return
    while((I2C0STAT)!= 0x18){;;} // Wait Slave Address+W, ACK
    I2C0DAT = Data; // Send Output Data to PCF8574A
    I2C0CONCLR = 0x0C; // Clear Acknowledge Bit + Interrupt Flag

    // Wait I2C Status Return
    while((I2C0STAT)!= 0x28){;;} // Wait Slave Address+W, ACK
    I2C0CONSET |= 0x10; // Send Stop Condition
    I2C0CONCLR = 0x0C; // Clear Acknowledge Bit + Interrupt Flag
    }

    Comment


    • Chao cac ban! Minh muon hoc hoi ARM va LPC 2148

      Duong hoan toan moi voi ARM va LPC 2148.
      minh moi mua LPC2148 ve dinh doc ARM choi.,...hong biet lam the nao de chay va tét...dung Keil thi lam the nao..Cac ban co the giup Duong tu dau toi cuoi de dung Keil chay LPC 2148 hong?
      Minh da co mdk323a Uvision3 Keil setup...cai vao may roi...roi lam the nao nua? minh co LPC 2148 va co UsB to DB9 adapter nua..Cac ban co the giup dum hong?
      Cam on nhieu

      Comment


      • Tốc độ i2c cua pca9633

        Chào các bạn!
        Cho mình hỏi về chế độ fast mode plus(1MHZ) i2c là sao? Và làm sao để khai báo chế độ đó trong con pca9633?Thanks.

        Comment


        • Em đang tìm hiểu về timer trong 2148 ,bác nào biết về timer trong 2148 có thể chỉ cho em với .

          Comment


          • Chào các bạn!
            Cho mình hỏi về chế độ fast mode plus(1MHZ) i2c là sao? Và làm sao để khai báo chế độ đó trong con pca9633?Thanks.
            Theo mình đã thử ; thì con số đó là tốc độ tối da cho phep giao tiep giữa PCA9633 và master khác!Còn tốc độ đạt tới 1Mhz hay không thì còn tùy thuôc vào master của bạn có support tới đó không!chứ không cần khai báo gì đâu!
            Mình đã thử và chạy được tới 1500Kbit với master là LPC922(một chú uC thuộc họ 8051) khi giao tiếp I2C với PCA9633

            còn nếu bạn dùng ARM lpc2000 thì I2C support tối đa có 400kbit hà!bạn có set cỡ nào đi chăng nữa thì nó cũng không đạt tới 1Mhz đâu

            Comment


            • MInh co bai ve UART0 --no se noi len Philip LPC khi minh noi voi Hyper tẻminal. Câc ban xem va co y kien, khi minh noi voi Hyper terminal thi no van chua hien len Philp LPC
              CAm on..

              /* Include header file depending upon device been used */
              #include"lpc214x.h"
              void Initialize(void);
              /* Macro Definitions */
              #define TEMT (1<<6)
              #define LINE_FEED 0xA
              #define CARRIAGE_RET 0xD
              /************************* MAIN *************************/
              int main()
              {
              int i;
              char c[]="Philips LPC";
              Initialize();
              /* Print forever */
              while(i<=1)
              {

              /* Keep Transmitting until Null character('\0') is reached */
              while(c[i])
              {
              U0THR=c[i];
              i++;
              }
              U0THR=LINE_FEED;
              U0THR=CARRIAGE_RET;
              /* Wait till U0THR and U0TSR are both empty */
              while(!(U0LSR & TEMT)){}
              }
              }
              /*************** System Initialization ***************/
              void Initialize()
              {
              /* Initialize Pin Select Block for Tx and Rx */
              PINSEL0=0x5;
              /* Enable FIFO's and reset them */
              U0FCR=0x7;
              /* Set DLAB and word length set to 8bits */
              U0LCR=0x83;
              /* Baud rate set to 9600 */
              U0DLL=0x10;
              U0DLM=0x0;
              /* Clear DLAB */
              U0LCR=0x3;
              }

              Comment


              • Tìm hiểu PCA9633

                Nguyên văn bởi hbaocr Xem bài viết
                Theo mình đã thử ; thì con số đó là tốc độ tối da cho phep giao tiep giữa PCA9633 và master khác!Còn tốc độ đạt tới 1Mhz hay không thì còn tùy thuôc vào master của bạn có support tới đó không!chứ không cần khai báo gì đâu!
                Mình đã thử và chạy được tới 1500Kbit với master là LPC922(một chú uC thuộc họ 8051) khi giao tiếp I2C với PCA9633

                còn nếu bạn dùng ARM lpc2000 thì I2C support tối đa có 400kbit hà!bạn có set cỡ nào đi chăng nữa thì nó cũng không đạt tới 1Mhz đâu
                Chao ban,
                Minh cung dang tim hieu ve con PCA9633, minh viet code cho I2C ma chi gui được địa chỉ của con PCA9633, mà kô truy xuất đc địa chỉ thanh ghi điều khiển của nó, khi mình truy xuất thì nó ko gửi ACK về, bạn có code về phần này ko. Gửi cho mình với. Thank nha.
                mail: danghung1986@yahoo.com

                Comment


                • co ai co the chi minh cach viet chuong tring PWM cho 2106 ko vay

                  Comment


                  • chào các huynh!
                    cho em hỏi : LPC22xx có thể mô phỏng trên proteus được không ? em dùng proteus 7.2 mà ko thấy hỗ trợ.
                    Thanks!
                    :-)

                    Comment


                    • @ boycdt04
                      Chao cac ban!
                      Cac ban biet o tphcm cho nao co ban modul wireless usb CYWUSB6935 khong ?
                      Bạn cần bao nhiêu con ?. Nếu ít mình có thể để lại. Giá cả sinh viên.

                      bạn có thể liên lạc với mình qua email: xuanhaidt2@yahoo.com
                      Last edited by xuanhaidt2; 07-11-2008, 14:36. Lý do: thêm email.

                      Comment


                      • chào các huynh!
                        cho em hỏi : LPC22xx có thể mô phỏng trên proteus được không ? em dùng proteus 7.2 mà ko thấy hỗ trợ.
                        proteus co LPC2138

                        ban co the mua mach that ma làm ma!hiennay co nheu cho cung ban lpc2148

                        Comment


                        • @vanhungbk
                          Chao ban,
                          Minh cung dang tim hieu ve con PCA9633, minh viet code cho I2C ma chi gui được địa chỉ của con PCA9633, mà kô truy xuất đc địa chỉ thanh ghi điều khiển của nó, khi mình truy xuất thì nó ko gửi ACK về, bạn có code về phần này ko. Gửi cho mình với. Thank nha.
                          đây là code viết trên lpc922(1 chú 8051 2 nguon xung clock)
                          Code:
                          include "reg922.h"
                          /***************************************************************************
                           * Section:  I2C
                           ***************************************************************************
                           * Description:
                           *     I2C Support routines
                           ***************************************************************************/
                          // define pin names  <EX1>
                          
                          sbit EX_INT1 = P1^4;
                          
                          enum {
                              I2C_IDLE=0,
                              I2C_ERROR=1,
                              I2C_OK=2,
                              I2C_BUSY=0x10,
                              I2C_BUSYTX=0x10,
                              I2C_BUSYRX=0x11
                          };
                          
                          unsigned char G_i2cSlaveAddress;
                          unsigned char *G_i2cData;
                          unsigned char G_i2cDataLength;
                          bit G_i2cDoneFlag;
                          unsigned char G_i2cStatus;
                          unsigned char G_i2cIndex;
                          
                          unsigned char index=0;//for ex_int1	   
                          unsigned char data_request[5];
                          
                          /***************************************************************************
                           * Section:  LED to setup the value of PCA9633 control register
                           ***************************************************************************
                           * Description:
                           *     LED support routines for the PCA9633	  no auto increase pointer
                           ***************************************************************************/
                          #define BASE_LED_ADDR       0x60    // 7 bit address, low 7 bits
                          #define ALL_CALL_ADDR       (0xE0>>1)
                          
                          // Registers on the PCA9633
                          #define LED_REG_MODE1       0x00  //point to Mode1 reg
                          #define LED_REG_MODE2       0x01  //point to Mode2 reg
                          #define LED_REG_PWM0        0x02  //point to PWM0 reg
                          #define LED_REG_PWM1        0x03
                          #define LED_REG_PWM2        0x04
                          #define LED_REG_PWM3        0x05
                          #define LED_REG_GRPPWM      0x06
                          #define LED_REG_GRPFREQ     0x07
                          #define LED_REG_LEDOUT      0x08
                          #define LED_REG_SUBADR1     0x09
                          #define LED_REG_SUBADR2     0x0A
                          #define LED_REG_SUBADR3     0x0B
                          #define LED_REG_ALLCALLADR  0x0C
                          
                          // Current PCA9633 LED driver I2C address
                          static unsigned char G_LEDAddr ;
                          
                          // Index of 0-7 to denote which LED driver board being accessed
                          static unsigned char G_LEDIndex ;
                          
                          
                          void I2CInit(void);
                          unsigned char I2CWrite(
                                          unsigned char aAddress, 
                                          unsigned char *aData, 
                                          unsigned char aLength);
                          bit I2CIsDone(void);
                          void I2CWaitTilDone(void);
                          
                          void LEDRegWrite(unsigned char Led_Addr,unsigned char aReg, unsigned char aValue);
                          void LED_inits(unsigned char led_addr);
                          void LED_set_color(unsigned char led_addr,unsigned char PWM0,unsigned char PWM1,unsigned char PWM2,unsigned char PWM3);
                          
                          void ports_init(void);
                          void delay(void) ;
                          void main(void)
                          {	
                          unsigned int i;
                            //ports_init();
                            I2CInit();
                            EX_INT1=1;//set input pin
                            P0=0xFF; //set input port
                            IP0H &= 0xFB;//set lowest prio for ex_int
                            IP0 &= 0xFB;
                            EX1 =1;//enable EX_int1
                            EA = 1 ;
                            LED_inits(0x5);
                            while(1)
                            {
                            LED_set_color(0x5,255,0,0,0);
                            for(i=1;i<250;i++)
                            {
                            delay();
                            }
                            LED_set_color(0x5,0,255,0,0);
                           
                            for(i=1;i<250;i++)
                            {
                            delay();
                            }
                          
                            LED_set_color(0x5,0,0,255,0);
                            
                            for(i=1;i<250;i++)
                            {
                            delay();
                            }
                            
                            LED_set_color(0x5,255,255,0,0);
                          
                             for(i=1;i<250;i++)
                            {
                            delay();
                            }
                          
                            LED_set_color(0x5,0,255,255,0);
                          
                             for(i=1;i<250;i++)
                            {
                            delay();
                            }
                          
                            LED_set_color(0x5,255,0,255,0);
                          
                             for(i=1;i<250;i++)
                            {
                            delay();
                            }
                          
                            LED_set_color(0x5,255,255,255,0);
                          
                             for(i=1;i<250;i++)
                            {
                            delay();
                            }
                          
                            LED_set_color(0x5,255,100,255,0);
                          
                             for(i=1;i<250;i++)
                            {
                            delay();
                            }
                          
                            }
                          
                          }
                          //Interrupt function
                          /*ex1 interupt to update data for led*/
                          void EX1_isr(void) interrupt 2
                          {
                          data_request[index]=P0;
                          if(index>=5)
                          {
                          index=0;
                          //configure led with data request from lpc2148
                          //LED_bar_component(data_request[0],data_request[1],data_request[2],data_request[3],data_request[4]);
                          }
                          else
                          {
                          index++;
                          }
                          }
                          /*-------------------------------------------------------------------------*
                           * Routine:  I2CInterrupt
                           *-------------------------------------------------------------------------*
                           * Description:
                           *      I2C interrupt service routine.  Handled as a state machine that
                           *      process steps based on the status of the I2C status register.
                           *-------------------------------------------------------------------------*/
                          void I2CInterrupt(void) interrupt 6 using 1
                          {
                              unsigned char status;
                          
                              status = I2STAT & 0xF8;
                          
                              switch(status)
                              {
                                  // Start condition tranmitted
                                  case 0x08:
                          
                                  // Repeat start condition transmitted
                                  case 0x10:
                                      // Send the slave address
                                      I2DAT = G_i2cSlaveAddress;
                                      STA = 0;
                                      STO = 0;
                                      G_i2cIndex = 0;
                                      break;
                          
                                  // MASTER TRANSMITTER
                                  // Slave Address + Write transmitted, and got ACK from slave
                                  case 0x18:
                                      // Transmit a byte
                                      I2DAT = G_i2cData[G_i2cIndex];
                                      STA = 0;
                                      STO = 0;
                                      break;
                          
                                  // Slave Address transmitted, no ACK received
                                  case 0x20:
                                      // Generate a stop condition and report error status
                                      STA = 0;
                                      STO = 1;
                                      G_i2cStatus = I2C_ERROR;
                                      G_i2cDoneFlag = 1;
                                      break;
                          
                                  // Data byte written and ACK received.
                                  case 0x28:
                                      // Last byte?
                                      if (G_i2cIndex >= G_i2cDataLength) {
                                          // Yes, last.  Generate a stop condition
                                          STA = 0;
                                          STO = 1;
                                          G_i2cStatus = I2C_OK;
                                          G_i2cDoneFlag = 1;
                                      }
                                      else
                                      {
                                          // Send the next byte
                                          G_i2cIndex++;
                                          I2DAT = G_i2cData[G_i2cIndex];
                                          STA = 0;
                                          STO = 0;
                                      }
                                      break;
                          
                                  // Data byte written but no ACK received
                                  case 0x30:
                                      // Generate a stop condition
                                      STA = 0;
                                      STO = 1;
                                      G_i2cStatus = I2C_ERROR;
                                      G_i2cDoneFlag = 1;
                                      break;
                          
                                  // Arbitration was lost
                                  case 0x38:
                                      // Generate a start condition and try again
                                      STA = 1;
                                      STO = 0;
                                      break;
                          
                                  // MASTER RECEIVER
                                  // Slave address + Read sent, ACK received
                                  case 0x40:
                                      // Are we to receive more?
                                      STA = 0;
                                      STO = 0;
                                      if (G_i2cIndex >= G_i2cDataLength)  {
                                          // No more needed.
                                          // return NACK for data byte
                                          AA = 0;
                                      } else {
                                          // More bytes needed.
                                          // return ACK for data byte
                                          AA = 1;
                                      }
                                      break;
                          
                                  // Slave address + Read sent, NO ACK received
                                  case 0x48:
                                      // Generate a stop condition
                                      STA = 0;
                                      STO = 1;
                                      G_i2cStatus = I2C_ERROR;
                                      G_i2cDoneFlag = 1;
                                      break;
                          
                                  // Data byte received with ACK
                                  case 0x50:
                                      // Store received byte
                                      G_i2cData[G_i2cIndex++] = I2DAT;
                          
                                      // Are we to receive more?
                                      STA = 0;
                                      STO = 0;
                                      if (G_i2cIndex >= G_i2cDataLength) {
                                          // return NACK for next data byte
                                          AA = 0;
                                      } else {
                                          // return ACK for next data byte
                                          AA = 1;
                                      } 
                                      break;
                          
                                  // Data byte received with NACK (last byte)
                                  case 0x58:
                                      // Store last byte
                                      G_i2cData[G_i2cIndex] = I2DAT;
                                      // Generate a stop condition, but report OK
                                      STA = 0;
                                      STO = 1;
                                      G_i2cStatus = I2C_OK;
                                      G_i2cDoneFlag = 1;
                                      break;
                          
                                  // Unhandled state
                                  default:
                                      // Generate a stop condition
                                      STA = 0;
                                      STO = 1;
                                      G_i2cStatus = I2C_ERROR;
                                      G_i2cDoneFlag = 1;
                                      break;
                              }
                          
                              // clear interrupt flag
                              SI = 0;
                          }
                          /*-------------------------------------------------------------------------*
                           * Routine:  I2CInit
                           *-------------------------------------------------------------------------*
                           * Description:
                           *      Setup the processor for doing I2C interrupt driven communications
                           *-------------------------------------------------------------------------*/
                          void I2CInit(void)
                          {
                           /*   // Set pins (PCL/PDA) to open drain
                              P1M1 |= 0x0C;
                              P1M2 |= 0x0C;
                          
                           /*   // configure internal SCL generator for 400 kHz (
                              I2SCLH = 0x05;
                              I2SCLL = 0x04;	  
                          	 // configure timer 1
                            TMOD &= 0x0F;					
                            // mode 1
                            TMOD |= 0x20;
                            // reload value f=12M/2/(256-TL1)=3000khz
                            TH1 = 0xFE;
                            TL1 = 0xFE;
                            // start timer 1
                            TR1 = 1;
                          
                            // configure I2C interface
                            // configure I2C interface (AA and I2EN are set)
                            // use timer 1
                            I2CON = 0x45;
                            // set interrupt priority to 0
                             IP1 &= ~0x01;
                             IP1H &=~0x01;
                          
                              // set initial status
                              G_i2cStatus = I2C_IDLE;
                          
                              // Turn on the I2C interrupt
                              EI2C = 1;	  */
                          
                          	// set pins to open-drain
                            P1M1 |= 0x0C;
                            P1M2 |= 0x0C;
                          
                            // configure I2C address
                            I2ADR = 0x00;
                            I2ADR = 0xFE;
                            // configure internal SCL generator
                            //I2SCLH = 0x08;
                            //I2SCLL = 0x07;
                          
                            // configure I2C interface
                            // use internal SCL generator
                           // I2CON = 0x44;
                            // set interrupt priority to 0
                             // configure timer 1
                            TMOD &= 0x0F;
                            // mode 1
                            TMOD |= 0x20;
                            // reload value
                            TH1 = 0xF1;
                            TL1 = 0xF1;
                            // start timer 1
                            TR1 = 1;
                          
                            // configure I2C interface
                            // use timer 1
                            I2CON = 0x45;
                          
                            IP1 &= ~0x01;
                            IP1H &= ~0x01;
                          
                            // initial status
                           G_i2cStatus = I2C_IDLE;
                          
                            // enable interrupt
                            EI2C = 1;
                          
                          }  //end i2c_init
                          
                          /*-------------------------------------------------------------------------*
                           * Routine:  I2CWrite
                           *-------------------------------------------------------------------------*
                           * Description:
                           *      Write a series of bytes out the I2C bus to the given slave address
                           * Inputs:
                           *      unsigned char aAddress    -- Address of slave
                           *      unsigned char *aData      -- Pointer to data to send
                           *      unsigned char aLength     -- Number of data bytes to write
                           * Outputs:
                           *      unsigned char             -- Status of I2C bus at start of write.
                           *                                   Returns I2C_OK if successful.
                           *-------------------------------------------------------------------------*/
                          unsigned char I2CWrite(
                                          unsigned char aAddress, 
                                          unsigned char *aData, 
                                          unsigned char aLength)
                          {
                              // Must be idle in order to send
                              if (G_i2cStatus & I2C_BUSY)
                                  return G_i2cStatus;
                          
                              // Mark busy
                              G_i2cStatus = I2C_BUSYTX;
                              G_i2cDoneFlag = 0;
                          
                              // Setup address to be sent to
                              G_i2cSlaveAddress = aAddress<<1;
                          
                              // Remember data and length
                              G_i2cData = aData;
                              G_i2cDataLength = aLength-1;
                          
                              // Start
                              STA = 1;
                          
                              return I2C_OK;
                          }	//end i2cwrite
                          
                          
                          
                          /*-------------------------------------------------------------------------*
                           * Routine:  I2CIsDone
                           *-------------------------------------------------------------------------*
                           * Description:
                           *      Returns true if the last I2C transaction is complete.
                           * Outputs:
                           *      bit                       -- 1 if complete, else 0
                           *-------------------------------------------------------------------------*/
                          bit I2CIsDone(void)
                          {
                              return G_i2cDoneFlag;
                          }
                          
                          /*-------------------------------------------------------------------------*
                           * Routine:  I2CWaitTilDone
                           *-------------------------------------------------------------------------*
                           * Description:
                           *      Blocks until the last I2C command completes.
                           *-------------------------------------------------------------------------*/
                          void I2CWaitTilDone(void)
                          {
                              while (!I2CIsDone())
                                  {; }
                          }
                          
                          /*-------------------------------------------------------------------------*
                           * Routine:  LEDRegWrite
                           *-------------------------------------------------------------------------*
                           * Description:
                           *      Set a register in the currently selected PCA9633 device(s).
                           *      Blocks until I2C command is completed.
                           * Inputs:
                           *      unsigned char aReg        -- Register to write
                           *      unsigned char aValue      -- Value of register.
                           *-------------------------------------------------------------------------*/
                          void LEDRegWrite(unsigned char Led_Addr,unsigned char aReg, unsigned char aValue)
                          {
                              char command[2] ;
                              command[0] = aReg ;	//reg addr of PCA96633
                              command[1] = aValue ;//value setup for reg of PCA9633 above
                          	G_LEDAddr=Led_Addr;
                              I2CWrite(G_LEDAddr, command, 2);
                              I2CWaitTilDone();
                          }
                          /*init PCA9633 with led_addr provide*/
                          void LED_inits(unsigned char led_addr)
                          {
                            // Standard reset
                              LEDRegWrite(led_addr,LED_REG_MODE1, 0x0F);//set pca9633 respond to allcall/subaddress1;2;3
                            // All addressing acceptable
                              LEDRegWrite(led_addr,LED_REG_MODE2, 0x05);//configure output 4 led/disable when OE=1/dimming
                              LEDRegWrite(led_addr,LED_REG_PWM0, 0x00);
                              LEDRegWrite(led_addr,LED_REG_PWM1, 0x00);
                              LEDRegWrite(led_addr,LED_REG_PWM2, 0x00);
                              LEDRegWrite(led_addr,LED_REG_PWM3, 0x00);
                              LEDRegWrite(led_addr,LED_REG_GRPPWM, 0xFF);//set duty of PWM of all 4e led/f=190Hz
                              LEDRegWrite(led_addr,LED_REG_GRPFREQ, 0x00);//set f of group but don't care because DMBLNK bit in mode2=0
                              LEDRegWrite(led_addr,LED_REG_LEDOUT,0x15); //0x15);  // all except amber are on
                              LEDRegWrite(led_addr,LED_REG_GRPFREQ, 0x00);//don't care
                          
                              // Reprogram the addresses for race tracks
                              LEDRegWrite(led_addr,LED_REG_SUBADR1, 0xB0+(2*(G_LEDIndex%2)));
                              LEDRegWrite(led_addr,LED_REG_SUBADR2, 0xC0+(2*(G_LEDIndex%3)));
                              LEDRegWrite(led_addr,LED_REG_SUBADR3, 0xD0+(2*(G_LEDIndex%4)));
                          
                              // Setup all call
                              LEDRegWrite(led_addr,LED_REG_ALLCALLADR,0xE1); //0xE1);
                          }
                          
                          /*set color for LED with RGBA*/
                          void LED_set_color(unsigned char led_addr,unsigned char PWM0,unsigned char PWM1,unsigned char PWM2,unsigned char PWM3)
                          {
                          unsigned char bits = 0x00;
                          
                              // All 4 leds allow independent and group PWM
                              if (PWM0)
                                  bits |= 0x03;
                              if (PWM1)
                                  bits |= 0x0C;
                              if (PWM2)
                                  bits |= 0x30;
                              if (PWM3)
                                  bits |= 0xC0;
                          
                              // Write the configuration of on/off bits
                              LEDRegWrite(led_addr,LED_REG_LEDOUT,bits);
                          
                              // Write the PWM values.
                              LEDRegWrite(led_addr,LED_REG_PWM0,PWM0);
                              LEDRegWrite(led_addr,LED_REG_PWM1,PWM1);
                              LEDRegWrite(led_addr,LED_REG_PWM2,PWM2);
                              LEDRegWrite(led_addr,LED_REG_PWM3,PWM3);
                          }
                          /*port init*/
                          void ports_init(void)
                          {
                            P0M1 &= 0x00;
                            P0M2 &= 0x00;
                            P1M1 |= 0x30;
                            P1M2 &= 0xCF;
                          } // ports_init
                          
                          void delay(void)
                          {
                          unsigned char k=255;
                          unsigned char i=1;
                          while(i--)
                           {
                           k=255;
                           while(k--);
                           }
                          }
                          còn bạn muốn viết trên ARM LPC2000 thì cũng được nhưng mình đã thử trên LPC2148 với PCA9633 tốc độ I2C của master LPC2000 chuối lắm có 400Kbits/s ah.Trong khi Chú LPC922 có tốc độ i2C tối đa tới 3000Kbits/s lận
                          cheer

                          Comment


                          • Sử dụng GLCD PCF8833 của nokia 6100

                            Xin chào các bác ; lâu nay bận làm luận văn tốt nghiệp nên chả pót bài nào!Hi; hôm nay mới bảo vệ luận văn xong; em xin pót tiếp bài về cách sử dụng GLCD PCF8833 của nokia 6100

                            Đặc Điểm GLCD graphic PCF8833 dùng cho NoKia 6100:
                            • Nguồn 3.3V
                            • Giao tiếp SPI , truyền data 9 bit
                            • 132x132 điểm ảnh với 12 bit màu RGB(4bit Red , 4 bit Green, 4 bit Blue)



                            Chú ý khi thiết kế nè:
                            1: Các bác có thể sử dụng IC đệm để có thể giao tiếp Được với 5V như 74lvc244 hay 74lvc245
                            2:Tuy su dung nguon la 3v nhưng chan Blink của nó phai cấp áp từ 7->9v nó mới chạy

                            • Hoạt động (các bác xem hình 2) :
                            Nokia 6100 sử dụng giao thức SPI (clock and data) hoạt động như 1 Slave nhận Command và Data từ Master là ARM LPC2214.Chúng ta Send 9 bit trên đường truyền SPI (truyền MSB trước) bao gồm MSB chỉ rõ là Data hay Command, và 8 bit cuối là dữ liệu truyền.
                            MSB=0 dữ liệu LCD nhận là Command
                            MSB=1 dữ liệu LCD nhận Data


                            Chúng ta hiển thị lên LCD bằng cách send lệnh trước và các đối số của lệnh sau
                            Chúng ta có thể Display như mong muốn bằng cách kiểm soát từng điểm ảnh trên màn hình LCD. Các Command thường dùng
                            #define NOP 0x00 // nop
                            #define SWRESET 0x01 // software reset
                            #define BSTROFF 0x02 // booster voltage OFF
                            #define BSTRON 0x03 // booster voltage ON
                            #define RDDIDIF 0x04 // read display identification
                            #define RDDST 0x09 // read display status
                            #define SLEEPIN 0x10 // sleep in
                            #define SLEEPOUT 0x11 // sleep out
                            #define PTLON 0x12 // partial display mode
                            #define NORON 0x13 // display normal mode
                            #define INVOFF 0x20 // inversion OFF
                            #define INVON 0x21 // inversion ON
                            #define DALO 0x22 // all pixel OFF
                            #define DAL 0x23 // all pixel ON
                            #define SETCON 0x25 // write contrast
                            #define DISPOFF 0x28 // display OFF
                            #define DISPON 0x29 // display ON
                            #define CASET 0x2A // column address set
                            #define PASET 0x2B // page address set
                            #define RAMWR 0x2C // memory write
                            #define RGBSET 0x2D // colour set
                            #define PTLAR 0x30 // partial area
                            #define VSCRDEF 0x33 // vertical scrolling definition
                            #define TEOFF 0x34 // test mode
                            #define TEON 0x35 // test mode
                            #define MADCTL 0x36 // memory access control
                            #define SEP 0x37 // vertical scrolling start address
                            #define IDMOFF 0x38 // idle mode OFF
                            #define IDMON 0x39 // idle mode ON
                            #define COLMOD 0x3A // interface pixel format
                            #define SETVOP 0xB0 // set Vop
                            #define BRS 0xB4 // bottom row swap
                            #define TRS 0xB6 // top row swap
                            #define DISCTR 0xB9 // display control
                            #define DOR 0xBA // data order
                            #define TCDFE 0xBD // enable/disable DF temperature compensation
                            #define TCVOPE 0xBF // enable/disable Vop temp comp
                            #define EC 0xC0 // internal or external oscillator
                            #define SETMUL 0xC2 // set multiplication factor
                            #define TCVOPAB 0xC3 // set TCVOP slopes A and B
                            #define TCVOPCD 0xC4 // set TCVOP slopes c and d
                            #define TCDF 0xC5 // set divider frequency
                            #define DF8COLOR 0xC6 // set divider frequency 8-color mode
                            #define SETBS 0xC7 // set bias system
                            #define RDTEMP 0xC8 // temperature read back
                            #define NLI 0xC9 // n-line inversion
                            #define RDID1 0xDA // read ID1
                            #define RDID2 0xDB // read ID2
                            #define RDID3 0xDC // read ID3
                            Xem chi tiết các lệnh ở datasheet PCF8833
                            Sơ đồ mạch ( đây chỉ là sơ đồ mạch đơn giản các bác thêm mắm thêm muối vô nhé)




                            Code thực hiện :
                            code dựa trên VĐK ARM LPC2000 nhưng các bác có thể sử dụng code này cho các VĐK khác kể cả 8051 vì GLCD này sử dụng giao thức SPI ; trong code thực hiện tuy viết trên ARM nhưng em ko sử dụng SPI mode của nó mà giả lập chức năng SPI trên các chân IO bình thường!Do đó các bác có thể dùng code này để phat trein tren các VDK khác ko ho tro SPI

                            Code:
                            #include <LPC22xx.H> 	                                // LPC2214 MPU Register
                            //define for LCD
                            /*****************************************************************************
                                      Command of LCD NOKIA6100(phillips chipset)
                            *****************************************************************************/
                            #define NOP       0x00 // nop
                            #define SWRESET    0x01 // software reset
                            #define BSTROFF    0x02 // booster voltage OFF
                            #define BSTRON       0x03 // booster voltage ON
                            #define RDDIDIF    0x04 // read display identification
                            #define RDDST       0x09 // read display status
                            #define SLEEPIN    0x10 // sleep in
                            #define SLEEPOUT    0x11 // sleep out
                            #define PTLON       0x12 // partial display mode
                            #define NORON       0x13 // display normal mode
                            #define INVOFF      0x20 // inversion OFF
                            #define INVON       0x21 // inversion ON
                            #define DALO       0x22 // all pixel OFF
                            #define DAL       0x23 // all pixel ON
                            #define SETCON       0x25 // write contrast
                            #define DISPOFF    0x28 // display OFF
                            #define DISPON       0x29 // display ON
                            #define CASET       0x2A // column address set
                            #define PASET       0x2B // page address set
                            #define RAMWR       0x2C // memory write
                            #define RGBSET       0x2D // colour set
                            #define PTLAR       0x30 // partial area
                            #define VSCRDEF    0x33 // vertical scrolling definition
                            #define TEOFF       0x34 // test mode
                            #define TEON       0x35 // test mode
                            #define MADCTL       0x36 // memory access control
                            #define SEP       0x37 // vertical scrolling start address
                            #define IDMOFF       0x38 // idle mode OFF
                            #define IDMON       0x39 // idle mode ON
                            #define COLMOD       0x3A // interface pixel format
                            #define SETVOP       0xB0 // set Vop
                            #define BRS       0xB4 // bottom row swap
                            #define TRS       0xB6 // top row swap
                            #define DISCTR       0xB9 // display control
                            #define DOR       0xBA // data order
                            #define TCDFE       0xBD // enable/disable DF temperature compensation
                            #define TCVOPE       0xBF // enable/disable Vop temp comp
                            #define EC          0xC0 // internal or external oscillator
                            #define SETMUL       0xC2 // set multiplication factor
                            #define TCVOPAB    0xC3 // set TCVOP slopes A and B
                            #define TCVOPCD    0xC4 // set TCVOP slopes c and d
                            #define TCDF       0xC5 // set divider frequency
                            #define DF8COLOR    0xC6 // set divider frequency 8-color mode
                            #define SETBS       0xC7 // set bias system
                            #define RDTEMP       0xC8 // temperature read back
                            #define NLI       0xC9 // n-line inversion
                            #define RDID1       0xDA // read ID1
                            #define RDID2       0xDB // read ID2
                            #define RDID3       0xDC // read ID3
                            //define color
                            // backlight control  
                            #define BKLGHT_LCD_ON        1
                            #define BKLGHT_LCD_OFF       2
                            
                            // Booleans
                            #define NOFILL		0
                            #define FILL		1
                            
                            // 12-bit color definitions
                            #define WHITE		0xFFF
                            #define BLACK		0x000
                            #define RED			0xF00
                            #define GREEN		0x0F0
                            #define BLUE		0x00F
                            #define CYAN		0x0FF
                            #define MAGENTA		0xF0F
                            #define YELLOW		0xFF0
                            #define BROWN		0xB22
                            #define ORANGE		0xFA0
                            #define	PINK		0xF6A		
                            
                            // Font sizes
                            #define SMALL		0
                            #define MEDIUM		1
                            #define	LARGE		2
                            
                            //define pin
                            #define RS (1<<21)
                            #define CS (1<<11)
                            #define BL (1<<22)
                            #define SDA       (1<<6) //MOSI
                            #define CLK       (1<<4) //CLK
                            //define program
                            //*****************************************************************************
                            //          Program definition
                            //*****************************************************************************/
                            #define LCD_CS_LOW IOCLR0  |= CS
                            #define LCD_CS_HIGH IOSET0 |= CS
                            
                            #define CLK0 IOCLR0 |= CLK
                            #define CLK1 IOSET0 |= CLK
                            
                            #define SDA0 IOCLR0 |= SDA
                            #define SDA1 IOSET0 |= SDA
                            
                            #define LCD_RESET_LOW IOCLR0 |= RS
                            #define LCD_RESET_HIGH IOSET0 |= RS 
                            
                            /* pototype  section */
                            //****************************************************************************
                            //          Program prototype
                            //******************FOR LCD PCF8833**********************************************************
                            void Send_Spi(unsigned int data);
                            void Backlight(unsigned char state);
                            void WriteSpiCommand(unsigned int data);
                            void WriteSpiData(unsigned int data);
                            void InitLcd(void);
                            void LCDWriteNum(int num, int  x, int  y, int size, int fcolor, int bcolor);
                            void LCDWrite130x130bmp(void);
                            void LCDClearScreen(void);
                            void LCDSetXY(int x, int y);
                            void LCDSetPixel(int  x, int  y, int  color);
                            void LCDSetLine(int x1, int y1, int x2, int y2, int color);
                            void LCDSetRect(int x0, int y0, int x1, int y1, unsigned char fill, int color);
                            void LCDSetCircle(int x0, int y0, int radius, int color);
                            void LCDPutChar(char c, int  x, int  y, int size, int fcolor, int bcolor);
                            void LCDPutStr(char *pString, int  x, int  y, int Size, int fColor, int bColor) ;
                            void LCD_Display_Arg(int x1, int y1, float x2, float y2, int color);
                            //*********************For ADC and ADXL*************************************************************
                            //CCLK=12xM=12x5=60MHZ
                            //PCLK=CCLK (VPBDIV=0x00)
                            int readpinport0(unsigned int portpin);
                            int outpinport0(unsigned int portpin,unsigned int val);
                            void Delay(unsigned long int);	// Delay Time Function
                            //********************************Finish prototype****************************************
                             
                            //******************VAriable for LCD display***************************************
                            const unsigned char FONT6x8[97][8] = {
                            
                            0x06,0x08,0x08,0x00,0x00,0x00,0x00,0x00,	//  columns, rows, num_bytes_per_char
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	space	0x20
                            0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00,	//	!
                            0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00,	//	"
                            0x50,0x50,0xF8,0x50,0xF8,0x50,0x50,0x00,	//	#	
                            0x20,0x78,0xA0,0x70,0x28,0xF0,0x20,0x00,	//	$
                            0xC0,0xC8,0x10,0x20,0x40,0x98,0x18,0x00,	//	%
                            0x40,0xA0,0xA0,0x40,0xA8,0x90,0x68,0x00,	//	&
                            0x30,0x30,0x20,0x40,0x00,0x00,0x00,0x00,	//	'
                            0x10,0x20,0x40,0x40,0x40,0x20,0x10,0x00,	//	(
                            0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x00,	//	)
                            0x00,0x20,0xA8,0x70,0x70,0xA8,0x20,0x00,	//	*
                            0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00,	//	+
                            0x00,0x00,0x00,0x00,0x30,0x30,0x20,0x40,	//	,
                            0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,	//	-
                            0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,	//	.
                            0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,	//	/ (forward slash)
                            0x70,0x88,0x88,0xA8,0x88,0x88,0x70,0x00,	//	0		0x30
                            0x20,0x60,0x20,0x20,0x20,0x20,0x70,0x00,	//	1
                            0x70,0x88,0x08,0x70,0x80,0x80,0xF8,0x00,	//	2
                            0xF8,0x08,0x10,0x30,0x08,0x88,0x70,0x00,	//	3
                            0x10,0x30,0x50,0x90,0xF8,0x10,0x10,0x00,	//	4
                            0xF8,0x80,0xF0,0x08,0x08,0x88,0x70,0x00,	//	5
                            0x38,0x40,0x80,0xF0,0x88,0x88,0x70,0x00,	//	6
                            0xF8,0x08,0x08,0x10,0x20,0x40,0x80,0x00,	//	7
                            0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00,	//	8
                            0x70,0x88,0x88,0x78,0x08,0x10,0xE0,0x00,	//	9
                            0x00,0x00,0x20,0x00,0x20,0x00,0x00,0x00,	//	:
                            0x00,0x00,0x20,0x00,0x20,0x20,0x40,0x00,	//	;
                            0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00,	//	<
                            0x00,0x00,0xF8,0x00,0xF8,0x00,0x00,0x00,	//	=
                            0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00,	//	>
                            0x70,0x88,0x08,0x30,0x20,0x00,0x20,0x00,	//	?
                            0x70,0x88,0xA8,0xB8,0xB0,0x80,0x78,0x00,	//	@		0x40
                            0x20,0x50,0x88,0x88,0xF8,0x88,0x88,0x00,	//	A
                            0xF0,0x88,0x88,0xF0,0x88,0x88,0xF0,0x00,	//	B
                            0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00,	//	C
                            0xF0,0x88,0x88,0x88,0x88,0x88,0xF0,0x00,	//	D
                            0xF8,0x80,0x80,0xF0,0x80,0x80,0xF8,0x00,	//	E
                            0xF8,0x80,0x80,0xF0,0x80,0x80,0x80,0x00,	//	F
                            0x78,0x88,0x80,0x80,0x98,0x88,0x78,0x00,	//	G
                            0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00,	//	H
                            0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00,	//	I
                            0x38,0x10,0x10,0x10,0x10,0x90,0x60,0x00,	//	J
                            0x88,0x90,0xA0,0xC0,0xA0,0x90,0x88,0x00,	//	K
                            0x80,0x80,0x80,0x80,0x80,0x80,0xF8,0x00,	//	L
                            0x88,0xD8,0xA8,0xA8,0xA8,0x88,0x88,0x00,	//	M
                            0x88,0x88,0xC8,0xA8,0x98,0x88,0x88,0x00,	//	N
                            0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00,	//	O
                            0xF0,0x88,0x88,0xF0,0x80,0x80,0x80,0x00,	//	P		0x50
                            0x70,0x88,0x88,0x88,0xA8,0x90,0x68,0x00,	//	Q
                            0xF0,0x88,0x88,0xF0,0xA0,0x90,0x88,0x00,	//	R
                            0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00,	//	S
                            0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x00,	//	T
                            0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00,	//	U
                            0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00,	//	V
                            0x88,0x88,0x88,0xA8,0xA8,0xA8,0x50,0x00,	//	W
                            0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00,	//	X
                            0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00,	//	Y
                            0xF8,0x08,0x10,0x70,0x40,0x80,0xF8,0x00,	//	Z
                            0x78,0x40,0x40,0x40,0x40,0x40,0x78,0x00,	//	[
                            0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,	//	\  (back slash)
                            0x78,0x08,0x08,0x08,0x08,0x08,0x78,0x00,	//	]	
                            0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00,	//	^
                            0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,	//	_
                            0x60,0x60,0x20,0x10,0x00,0x00,0x00,0x00,	//	`		0x60
                            0x00,0x00,0x60,0x10,0x70,0x90,0x78,0x00,	//	a
                            0x80,0x80,0xB0,0xC8,0x88,0xC8,0xB0,0x00,	//	b
                            0x00,0x00,0x70,0x88,0x80,0x88,0x70,0x00,	//	c
                            0x08,0x08,0x68,0x98,0x88,0x98,0x68,0x00,	//	d
                            0x00,0x00,0x70,0x88,0xF8,0x80,0x70,0x00,	//	e
                            0x10,0x28,0x20,0x70,0x20,0x20,0x20,0x00,	//	f
                            0x00,0x00,0x70,0x98,0x98,0x68,0x08,0x70,	//	g
                            0x80,0x80,0xB0,0xC8,0x88,0x88,0x88,0x00,	//	h
                            0x20,0x00,0x60,0x20,0x20,0x20,0x70,0x00,	//	i
                            0x10,0x00,0x10,0x10,0x10,0x90,0x60,0x00,	//	j
                            0x80,0x80,0x90,0xA0,0xC0,0xA0,0x90,0x00,	//	k
                            0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00,	//	l
                            0x00,0x00,0xD0,0xA8,0xA8,0xA8,0xA8,0x00,	//	m
                            0x00,0x00,0xB0,0xC8,0x88,0x88,0x88,0x00,	//	n
                            0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00,	//	o
                            0x00,0x00,0xB0,0xC8,0xC8,0xB0,0x80,0x80,	//	p		0x70
                            0x00,0x00,0x68,0x98,0x98,0x68,0x08,0x08,	//	q
                            0x00,0x00,0xB0,0xC8,0x80,0x80,0x80,0x00,	//	r
                            0x00,0x00,0x78,0x80,0x70,0x08,0xF0,0x00,	//	s
                            0x20,0x20,0xF8,0x20,0x20,0x28,0x10,0x00,	//	t
                            0x00,0x00,0x88,0x88,0x88,0x98,0x68,0x00,	//	u
                            0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00,	//	v
                            0x00,0x00,0x88,0x88,0xA8,0xA8,0x50,0x00,	//	w
                            0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00,	//	x
                            0x00,0x00,0x88,0x88,0x78,0x08,0x88,0x70,	//	y
                            0x00,0x00,0xF8,0x10,0x20,0x40,0xF8,0x00,	//	z
                            0x10,0x20,0x20,0x40,0x20,0x20,0x10,0x00,	//	{
                            0x20,0x20,0x20,0x00,0x20,0x20,0x20,0x00,	//	|
                            0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00,	//	}
                            0x40,0xA8,0x10,0x00,0x00,0x00,0x00,0x00,	//	~
                            0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00};	//	DEL
                            
                            const unsigned char FONT8x8[97][8] = {
                            
                            0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,	//  columns, rows, num_bytes_per_char
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	space	0x20
                            0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00,	//	!
                            0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00,	//	"
                            0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00,	//	#	
                            0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00,	//	$
                            0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00,	//	%
                            0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00,	//	&
                            0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,	//	'
                            0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00,	//	(
                            0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00,	//	)
                            0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00,	//	*
                            0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00,	//	+
                            0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30,	//	,
                            0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,	//	-
                            0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,	//	.
                            0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00,	//	/ (forward slash)
                            0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00,	//	0		0x30
                            0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00,	//	1
                            0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00,	//	2
                            0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00,	//	3
                            0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00,	//	4
                            0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00,	//	5
                            0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00,	//	6
                            0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00,	//	7
                            0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00,	//	8
                            0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00,	//	9
                            0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00,	//	:
                            0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30,	//	;
                            0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00,	//	<
                            0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,	//	=
                            0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00,	//	>
                            0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00,	//	?
                            0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00,	//	@		0x40
                            0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00,	//	A
                            0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00,	//	B
                            0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00,	//	C
                            0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00,	//	D
                            0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00,	//	E
                            0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00,	//	F
                            0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00,	//	G
                            0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00,	//	H
                            0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,	//	I
                            0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,	//	J
                            0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00,	//	K
                            0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00,	//	L
                            0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00,	//	M
                            0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00,	//	N
                            0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,	//	O
                            0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00,	//	P		0x50
                            0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00,	//	Q
                            0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00,	//	R
                            0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00,	//	S
                            0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00,	//	T
                            0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00,	//	U
                            0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,	//	V
                            0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00,	//	W
                            0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00,	//	X
                            0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00,	//	Y
                            0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00,	//	Z
                            0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,	//	[
                            0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,	//	\  (back slash)
                            0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,	//	]	
                            0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,	//	^
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,	//	_
                            0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,	//	`		0x60
                            0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00,	//	a
                            0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00,	//	b
                            0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00,	//	c
                            0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00,	//	d
                            0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00,	//	e
                            0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00,	//	f
                            0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C,	//	g
                            0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00,	//	h
                            0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00,	//	i
                            0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C,	//	j
                            0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00,	//	k
                            0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,	//	l
                            0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00,	//	m
                            0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00,	//	n
                            0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00,	//	o
                            0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78,	//	p		0x70
                            0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F,	//	q
                            0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00,	//	r
                            0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00,	//	s
                            0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00,	//	t
                            0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00,	//	u
                            0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00,	//	v
                            0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00,	//	w
                            0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00,	//	x
                            0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C,	//	y
                            0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00,	//	z
                            0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00,	//	{
                            0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00,	//	|
                            0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00,	//	}
                            0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00,	//	~
                            0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00};	//	DEL
                            
                            const unsigned char FONT8x16[97][16] = {
                            
                            0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//  columns, rows, num_bytes_per_char
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	space	0x20
                            0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,	//	!
                            0x00,0x63,0x63,0x63,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	"
                            0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00,	//	#	
                            0x0C,0x0C,0x3E,0x63,0x61,0x60,0x3E,0x03,0x03,0x43,0x63,0x3E,0x0C,0x0C,0x00,0x00,	//	$
                            0x00,0x00,0x00,0x00,0x00,0x61,0x63,0x06,0x0C,0x18,0x33,0x63,0x00,0x00,0x00,0x00,	//	%
                            0x00,0x00,0x00,0x1C,0x36,0x36,0x1C,0x3B,0x6E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,	//	&
                            0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	'
                            0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00,0x00,0x00,	//	(
                            0x00,0x00,0x18,0x0C,0x0C,0x06,0x06,0x06,0x06,0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,	//	)
                            0x00,0x00,0x00,0x00,0x42,0x66,0x3C,0xFF,0x3C,0x66,0x42,0x00,0x00,0x00,0x00,0x00,	//	*
                            0x00,0x00,0x00,0x00,0x18,0x18,0x18,0xFF,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,	//	+
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00,	//	,
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	-
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,	//	.
                            0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,	//	/ (forward slash)
                            0x00,0x00,0x3E,0x63,0x63,0x63,0x6B,0x6B,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,	//	0		0x30
                            0x00,0x00,0x0C,0x1C,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,0x00,0x00,	//	1
                            0x00,0x00,0x3E,0x63,0x03,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00,	//	2
                            0x00,0x00,0x3E,0x63,0x03,0x03,0x1E,0x03,0x03,0x03,0x63,0x3E,0x00,0x00,0x00,0x00,	//	3
                            0x00,0x00,0x06,0x0E,0x1E,0x36,0x66,0x66,0x7F,0x06,0x06,0x0F,0x00,0x00,0x00,0x00,	//	4
                            0x00,0x00,0x7F,0x60,0x60,0x60,0x7E,0x03,0x03,0x63,0x73,0x3E,0x00,0x00,0x00,0x00,	//	5
                            0x00,0x00,0x1C,0x30,0x60,0x60,0x7E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,	//	6
                            0x00,0x00,0x7F,0x63,0x03,0x06,0x06,0x0C,0x0C,0x18,0x18,0x18,0x00,0x00,0x00,0x00,	//	7
                            0x00,0x00,0x3E,0x63,0x63,0x63,0x3E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,	//	8
                            0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x3F,0x03,0x03,0x06,0x3C,0x00,0x00,0x00,0x00,	//	9
                            0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,	//	:
                            0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00,	//	;
                            0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00,	//	<
                            0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,	//	=
                            0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00,	//	>
                            0x00,0x00,0x3E,0x63,0x63,0x06,0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,0x00,0x00,	//	?
                            0x00,0x00,0x3E,0x63,0x63,0x6F,0x6B,0x6B,0x6E,0x60,0x60,0x3E,0x00,0x00,0x00,0x00,	//	@		0x40
                            0x00,0x00,0x08,0x1C,0x36,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x00,0x00,0x00,0x00,	//	A
                            0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x33,0x33,0x33,0x33,0x7E,0x00,0x00,0x00,0x00,	//	B
                            0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x60,0x60,0x61,0x33,0x1E,0x00,0x00,0x00,0x00,	//	C
                            0x00,0x00,0x7C,0x36,0x33,0x33,0x33,0x33,0x33,0x33,0x36,0x7C,0x00,0x00,0x00,0x00,	//	D
                            0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00,	//	E
                            0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,	//	F
                            0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x6F,0x63,0x63,0x37,0x1D,0x00,0x00,0x00,0x00,	//	G
                            0x00,0x00,0x63,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00,	//	H
                            0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,	//	I
                            0x00,0x00,0x0F,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00,	//	J
                            0x00,0x00,0x73,0x33,0x36,0x36,0x3C,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00,	//	K
                            0x00,0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00,	//	L
                            0x00,0x00,0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00,	//	M
                            0x00,0x00,0x63,0x63,0x73,0x7B,0x7F,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00,	//	N
                            0x00,0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,0x00,0x00,	//	O
                            0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,	//	P		0x50
                            0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x63,0x6B,0x6F,0x3E,0x06,0x07,0x00,0x00,	//	Q
                            0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00,	//	R
                            0x00,0x00,0x3E,0x63,0x63,0x30,0x1C,0x06,0x03,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,	//	S
                            0x00,0x00,0xFF,0xDB,0x99,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,	//	T
                            0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,	//	U
                            0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x08,0x00,0x00,0x00,0x00,	//	V
                            0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x36,0x00,0x00,0x00,0x00,	//	W
                            0x00,0x00,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x00,0x00,0x00,0x00,	//	X
                            0x00,0x00,0xC3,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,	//	Y
                            0x00,0x00,0x7F,0x63,0x43,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00,	//	Z
                            0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,	//	[
                            0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00,	//	\  (back slash)
                            0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00,	//	]	
                            0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	^
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,	//	_
                            0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	`		0x60
                            0x00,0x00,0x00,0x00,0x00,0x3C,0x46,0x06,0x3E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,	//	a
                            0x00,0x00,0x70,0x30,0x30,0x3C,0x36,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,0x00,0x00,	//	b
                            0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x60,0x60,0x60,0x63,0x3E,0x00,0x00,0x00,0x00,	//	c
                            0x00,0x00,0x0E,0x06,0x06,0x1E,0x36,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,	//	d
                            0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x7E,0x60,0x63,0x3E,0x00,0x00,0x00,0x00,	//	e
                            0x00,0x00,0x1C,0x36,0x32,0x30,0x7C,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,	//	f
                            0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x66,0x3C,0x00,0x00,	//	g
                            0x00,0x00,0x70,0x30,0x30,0x36,0x3B,0x33,0x33,0x33,0x33,0x73,0x00,0x00,0x00,0x00,	//	h
                            0x00,0x00,0x0C,0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,	//	i
                            0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,	//	j
                            0x00,0x00,0x70,0x30,0x30,0x33,0x33,0x36,0x3C,0x36,0x33,0x73,0x00,0x00,0x00,0x00,	//	k
                            0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,	//	l
                            0x00,0x00,0x00,0x00,0x00,0x6E,0x7F,0x6B,0x6B,0x6B,0x6B,0x6B,0x00,0x00,0x00,0x00,	//	m
                            0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x33,0x33,0x00,0x00,0x00,0x00,	//	n
                            0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00,	//	o
                            0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x30,0x78,0x00,0x00,	//	p		0x70
                            0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00,0x00,	//	q
                            0x00,0x00,0x00,0x00,0x00,0x6E,0x3B,0x33,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00,	//	r
                            0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x38,0x0E,0x03,0x63,0x3E,0x00,0x00,0x00,0x00,	//	s
                            0x00,0x00,0x08,0x18,0x18,0x7E,0x18,0x18,0x18,0x18,0x1B,0x0E,0x00,0x00,0x00,0x00,	//	t
                            0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00,	//	u
                            0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x36,0x36,0x1C,0x1C,0x08,0x00,0x00,0x00,0x00,	//	v
                            0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x00,0x00,0x00,0x00,	//	w
                            0x00,0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,	//	x
                            0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x3F,0x03,0x06,0x3C,0x00,0x00,	//	y
                            0x00,0x00,0x00,0x00,0x00,0x7F,0x66,0x0C,0x18,0x30,0x63,0x7F,0x00,0x00,0x00,0x00,	//	z
                            0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00,	//	{
                            0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,	//	|
                            0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18,0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00,	//	}
                            0x00,0x00,0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	//	~
                            0x00,0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};	//	DEL
                            unsigned char count;
                            unsigned int dat_count,somau;
                            unsigned int value;
                            //================ham chinh==========================
                            int main(void)
                            { 
                            
                            //******************FUNCTION for LCD***************************** 
                            // Initialize SPI interface to LCD
                            	IO0DIR|= CS|BL|RS|CLK|SDA;//SET OUTPUT PIN
                            	IO0SET|=CS|BL|RS|CLK|SDA;
                            	IO0CLR|= CLK|SDA;//int SPI
                            	IO0DIR&=~(1<<7);//set inputpin
                            	InitLcd();
                            	LCDSetRect(1, 1, 132, 132, FILL,BLACK );
                            	LCDPutStr("HELLO",10,1,1,RED,BLACK);
                            	LCDPutStr("Huynh Bao",1,1,1,RED,BLACK);
                            	LCDPutStr("PCF8833",120,1,1,RED,BLACK);
                            	while(1);
                            	
                            }	  
                            //==========================END OF MAIN FUNCTION==============================
                            //-------------read pin function-------------
                            int readpinport0(unsigned int portpin)
                            {
                            	unsigned long  p;
                            	IODIR0&=~(1<<portpin);	//set input
                            	p=IOPIN0;  //doc trang thai port 0
                            	p=(p&(1<<portpin))>>portpin;// kiem tra bit p0.5						         
                            	return (p) ;
                            }
                            //----------------write pin------------------
                            //out
                            int outpinport0(unsigned int portpin,unsigned int val)
                            {
                            	IODIR0|=1<<portpin;	//set output
                            	if (val)
                            	IOSET0|=1<<portpin;
                            	else
                            	IOCLR0|=1<<portpin;  
                            	return (1) ;
                            }
                            //=============spi control function 9 bit num and MSB first ==================
                            void Send_Spi(unsigned int data)	  
                            {
                            unsigned char bitnum=9;
                            unsigned int MSB;
                            unsigned char cho=5;
                            while(bitnum--)
                            	{
                            	MSB=(data>>bitnum)&0x0001;
                            	
                            	if (MSB)
                            	IO0SET|=SDA;
                            	else
                             	IO0CLR|=SDA;
                            	
                            	IO0SET|=CLK;
                            //	while(cho--); //delay
                            	IO0CLR|=CLK;
                            	}
                            }
                            
                            //================Write Command============================
                            void WriteSpiCommand(unsigned int data)
                            {	 
                            /*	 unsigned int com;
                            	 LCD_CS_LOW;
                            	 Delay(1);
                            	 com=	data & ~0x0100;// For Command MSB "LOW"
                               	 S0SPDR =  com;
                                 while((S0SPSR & 0x80)!= 0x80){;;}   // Wait SPIF = 1 (SPI Send Complete)
                            	 Delay(1);
                            	 LCD_CS_HIGH;*/
                            	   LCD_CS_LOW;
                              	   Send_Spi(data & ~0x0100);
                            	   LCD_CS_HIGH;
                            
                            }
                            //=============end function================
                            
                            //write data to LCD
                            void WriteSpiData(unsigned int data)
                            {
                             /* LCD_CS_LOW;
                              Delay(1);
                              S0SPDR  = data | 0x0100;// For Data MSB must "HIGH"
                               while((S0SPSR & 0x80)!= 0x80){;;}   // Wait SPIF = 1 (SPI Send Complete)
                               Delay(1);
                              LCD_CS_HIGH;*/
                              LCD_CS_LOW;
                              Send_Spi(data | 0x0100);
                              LCD_CS_HIGH;
                            }
                            //================end function=============
                            
                            //LCD blink
                            //	   Inputs:	state  -  1 = backlight on
                            //						  2 = backlight off
                            void Backlight(unsigned char state)
                            {
                            if(state==1)
                            IOSET0 = BL;	   //on
                            else
                            IOCLR0 = BL;	  //off
                            }
                            //=====================end function======== 
                            
                            //==================Int LCD===================
                            
                            void InitLcd(void) 
                            {   // Hardware reset
                              LCD_RESET_LOW;
                              Delay(10);
                              LCD_RESET_HIGH;
                              Delay(10);
                              WriteSpiCommand(SWRESET);
                              Delay(10);
                              // Sleep out  (command 0x11)
                            
                               WriteSpiCommand(SLEEPOUT);
                              // WriteSpiCommand(BSTRON);// booster vol on
                               Delay(10);
                            
                              // Inversion on  (command 0x20)
                              WriteSpiCommand(INVON);		// seems to be required for this controller
                            
                              // Color Interface Pixel Format  (command 0x3A)
                              WriteSpiCommand(COLMOD);
                              WriteSpiData(0x03);			// 0x03 = 12 bits-per-pixel
                            
                              // Memory access controler  (command 0x36)
                              WriteSpiCommand(MADCTL);
                              WriteSpiData(0xC8);			// 0xC0 = mirror x and y, reverse rgb
                              
                              // Write contrast  (command 0x25)
                              WriteSpiCommand(SETCON);
                              WriteSpiData(0x30);			// contrast 0x30 
                              Delay(10);
                            
                              // Display On  (command 0x29)
                              WriteSpiCommand(DISPON);
                              Delay(10);
                             
                            }
                            //======================end funtion===============
                            
                            
                            void LCDSetXY(int  x, int  y) {
                            	
                            	// Row address set  (command 0x2B)
                            	WriteSpiCommand(PASET);
                            	WriteSpiData(x);
                            	WriteSpiData(x);
                            
                            	// Column address set  (command 0x2A)
                            	WriteSpiCommand(CASET);
                            	WriteSpiData(y);
                            	WriteSpiData(y);
                            }
                            
                            void LCDSetPixel(int  x, int  y, int  color) {
                            
                            	LCDSetXY(x, y);
                            	WriteSpiCommand(RAMWR);
                            	WriteSpiData((unsigned char)((color >> 4) & 0xFFFF));
                            	WriteSpiData((unsigned char)(((color & 0x0F) << 4) | 0x00));
                            	WriteSpiCommand(NOP);
                            }
                            
                            void LCDSetLine(int x0, int y0, int x1, int y1, int color) {
                            
                                    int dy = y1 - y0;
                                    int dx = x1 - x0;
                                    int stepx, stepy;
                            
                                    if (dy < 0) { dy = -dy;  stepy = -1; } else { stepy = 1; }
                                    if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }
                                    dy <<= 1;							// dy is now 2*dy
                                    dx <<= 1;							// dx is now 2*dx
                            
                            		LCDSetPixel(x0, y0, color);
                                    if (dx > dy) 
                            		{
                                        int fraction = dy - (dx >> 1);	// same as 2*dy - dx
                                        while (x0 != x1) 
                            			{
                                            if (fraction >= 0) 
                            				{
                                                y0 += stepy;
                                                fraction -= dx;			// same as fraction -= 2*dx
                                            }
                                            x0 += stepx;
                                            fraction += dy;				// same as fraction -= 2*dy
                                            LCDSetPixel(x0, y0, color);
                                        }
                                    } 
                            		else 
                            		{
                                        int fraction = dx - (dy >> 1);
                                        while (y0 != y1) 
                            			{
                                            if (fraction >= 0) 
                            				{
                                                x0 += stepx;
                                                fraction -= dy;
                                            }
                                            y0 += stepy;
                                            fraction += dx;
                                            LCDSetPixel(x0, y0, color);
                                        }
                                    }
                            }
                            
                            void LCDSetRect(int x0, int y0, int x1, int y1, unsigned char fill, int color) 
                            {
                            	int 	xmin, xmax, ymin, ymax;
                            	int		i;
                            	
                            	// check if the rectangle is to be filled
                            	if (fill == FILL) 
                            		{
                            		xmin = (x0 <= x1) ? x0 : x1;
                            		xmax = (x0 > x1) ? x0 : x1;
                            		ymin = (y0 <= y1) ? y0 : y1;
                            		ymax = (y0 > y1) ? y0 : y1;
                            		WriteSpiCommand(PASET);
                            		WriteSpiData(xmin);
                            		WriteSpiData(xmax);
                            	 	WriteSpiCommand(CASET);
                            		WriteSpiData(ymin);
                            		WriteSpiData(ymax);
                            		// WRITE MEMORY
                            		WriteSpiCommand(RAMWR);
                            		// loop on total number of pixels / 2
                            		for (i = 0; i < ((((xmax - xmin + 1) * (ymax - ymin + 1)) / 2) + 1); i++) 
                            			{
                            			// use the color value to output three data bytes covering two pixels
                            			WriteSpiData((color >> 4) & 0xFF);
                            			WriteSpiData(((color & 0xF) << 4) | ((color >> 8) & 0xF));
                            			WriteSpiData(color & 0xFF);
                            			}
                            
                            	} 
                            	else 
                            	{
                               	
                               		// best way to draw un unfilled rectangle is to draw four lines
                            		LCDSetLine(x0, y0, x1, y0, color);
                            		LCDSetLine(x0, y1, x1, y1, color);
                            		LCDSetLine(x0, y0, x0, y1, color);
                            		LCDSetLine(x1, y0, x1, y1, color);
                                }
                            }
                            void LCDSetCircle(int x0, int y0, int radius, int color) 
                            {
                            	int f = 1 - radius;
                            	int ddF_x = 0;
                            	int ddF_y = -2 * radius;
                            	int x = 0;
                            	int y = radius;
                             
                            	LCDSetPixel(x0, y0 + radius, color);
                            	LCDSetPixel(x0, y0 - radius, color);
                            	LCDSetPixel(x0 + radius, y0, color);
                            	LCDSetPixel(x0 - radius, y0, color);
                             
                            	while(x < y) 
                            	{
                            		if(f >= 0) 
                            		{
                            			y--;
                            			ddF_y += 2;
                            			f += ddF_y;
                            		}
                            		x++;
                            		ddF_x += 2;
                            		f += ddF_x + 1;    
                            		LCDSetPixel(x0 + x, y0 + y, color);
                            		LCDSetPixel(x0 - x, y0 + y, color);
                            		LCDSetPixel(x0 + x, y0 - y, color);
                            		LCDSetPixel(x0 - x, y0 - y, color);
                            		LCDSetPixel(x0 + y, y0 + x, color);
                            		LCDSetPixel(x0 - y, y0 + x, color);
                            		LCDSetPixel(x0 + y, y0 - x, color);
                            		LCDSetPixel(x0 - y, y0 - x, color);
                            	}
                            }
                            
                            void LCDPutChar(char c, int  x, int  y, int size, int fColor, int bColor) {
                            	int					i,j;
                            	unsigned int		nCols;
                            	unsigned int		nRows;
                            	unsigned int		nBytes;
                            	unsigned char		PixelRow;
                            	unsigned char		Mask;
                            	unsigned int		Word0;
                            	unsigned int		Word1;
                            	unsigned char		*pFont;
                            	unsigned char		*pChar;
                            	unsigned char		*FontTable[] = {(unsigned char *)FONT6x8, (unsigned char *)FONT8x8, (unsigned char *)FONT8x16}; 
                            	
                            	// get pointer to the beginning of the selected font table
                            	pFont = (unsigned char *)FontTable[size];	
                            	
                            	// get the nColumns, nRows and nBytes
                            	nCols = *pFont;
                            	nRows = *(pFont + 1);
                            	nBytes = *(pFont + 2);
                            
                            	// get pointer to the last byte of the desired character
                            	pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;
                            	
                            	// Row address set  (command 0x2B)
                            	WriteSpiCommand(PASET);
                            	WriteSpiData(x);
                            	WriteSpiData(x + nRows - 1);
                              
                            	// Column address set  (command 0x2A)
                            	WriteSpiCommand(CASET);
                            	WriteSpiData(y);
                            	WriteSpiData(y + nCols - 1);
                            	
                            	// WRITE MEMORY
                            	WriteSpiCommand(RAMWR);
                            	
                            	// loop on each row, working backwards from the bottom to the top
                            	for (i = nRows - 1; i >= 0; i--) 
                            	{
                            		
                            		// copy pixel row from font table and then decrement row
                            		PixelRow = *pChar--;
                            	
                            		// loop on each pixel in the row (left to right)
                            		// Note: we do two pixels each loop
                            		Mask = 0x80;
                            		for (j = 0; j < nCols; j += 2) {
                            		
                            			// if pixel bit set, use foreground color; else use the background color
                            			// now get the pixel color for two successive pixels
                            			if ((PixelRow & Mask) == 0)
                            				Word0 = bColor;
                            			else
                            				Word0 = fColor;
                            			Mask = Mask >> 1;
                            			if ((PixelRow & Mask) == 0)
                            				Word1 = bColor;
                            			else
                            				Word1 = fColor;
                            			Mask = Mask >> 1;
                            			
                            			// use this information to output three data bytes
                            			WriteSpiData((Word0 >> 4) & 0xFF);
                            			WriteSpiData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
                            			WriteSpiData(Word1 & 0xFF);
                            		}	
                            	}
                            	// terminate the Write Memory command
                            	WriteSpiCommand(NOP);	
                            }
                            void LCDPutStr(char *pString, int  x, int  y, int Size, int fColor, int bColor) 
                            {
                            						
                            	// loop until null-terminator is seen
                            	while (*pString != 0x00) 
                            	{
                            
                            		// draw the character
                            		LCDPutChar(*pString++, x, y, Size, fColor, bColor);	
                            
                            		// advance the y position
                            		if (Size == SMALL)
                            			y = y + 6;
                            		else if (Size == MEDIUM)
                            			y = y + 8;
                            		else
                            			y = y + 8;
                            		
                            		// bail out if y exceeds 131
                            		if (y > 131) 
                            		
                            		break;
                            	}
                            }
                            //****************LCD write Num***************************
                            void LCDWriteNum(int num, int  x, int  y, int size, int fcolor, int bcolor)
                            {
                            unsigned char dv,chuc,tram;
                            if (num>=0)
                            		{
                            		LCDPutChar(' ',x,y,size,fcolor,bcolor);
                            		}
                            else
                            		{
                            		LCDPutChar('-',x,y,size,fcolor,bcolor);
                            		num=-num;
                            		}
                            		 dv=num%10;
                            		 chuc=((num-dv)/10)%10;
                            		 tram=(num-dv-10*chuc)/100;
                            		 LCDPutChar(tram+48,x,y+8,size,fcolor,bcolor);
                            		 LCDPutChar('.',x,y+16,size,fcolor,bcolor);
                            		 LCDPutChar(chuc+48,x,y+24,size,fcolor,bcolor);
                            		 LCDPutChar(dv+48,x,y+32,size,fcolor,bcolor);
                            
                            }
                            //========Write huong chuyen dong====================
                            void LCD_Display_Arg(int x1, int y1, float x2, float y2, int color)
                            {
                            int xdp,ydp;
                            //rescale  -1.2g  1.2g full scale
                            xdp=floor(0.30*x2+60);//for -2g 2g thi 20x+40
                            ydp=floor(0.30*y2+60);
                            LCDSetLine(x1,y1,xdp,ydp,color) ;
                            }
                            void LCDWrite130x130bmp(void) {
                            	
                            	long	j;			// loop counter
                            	// Memory access controler  (command 0x36)
                              	WriteSpiCommand(MADCTL);
                              	WriteSpiData(0x48);     // no mirror Y (temporary to satisfy Olimex bmptoarray utility)
                            	// Display OFF
                            	WriteSpiCommand(DISPOFF);
                            	// Column address set  (command 0x2A)
                            	WriteSpiCommand(CASET);
                            	WriteSpiData(0);
                            	WriteSpiData(131);
                            	// Page address set  (command 0x2B)
                            	WriteSpiCommand(PASET);
                            	WriteSpiData(0);
                            	WriteSpiData(131);
                              	// WRITE MEMORY
                            	WriteSpiCommand(RAMWR);
                            
                            	for(j = 0; j < sizeof(bmp); j++) {
                            		WriteSpiData(bmp[j]);
                            	}
                            	// Memory access controler  (command 0x36)
                              	WriteSpiCommand(MADCTL);
                              	WriteSpiData(0xC8);     // restore to (mirror x and y, reverse rgb)
                            	// Display On
                            	WriteSpiCommand(DISPON);	
                            }
                            void Delay(unsigned long int count1)
                            {
                            unsigned long int i,k;
                            k=count1*5200;
                              for(i=0;i<k;i++);	// Loop Decrease Counter	
                            }

                            Comment


                            • Bạn có thể thay thế phần chip của PHILIP thành EPSON để điều khiển LCD dòng chip S1D15G00 :
                              Đây là phần khai báo :
                              //************************************************** ******************
                              //
                              // EPSON Controller Definitions
                              //
                              //************************************************** ******************
                              #define DISON 0xAF
                              #define DISOFF 0xAE
                              #define DISNOR 0xA6
                              #define DISINV 0xA7
                              #define SLPIN 0x95
                              #define SLPOUT 0x94
                              #define COMSCN 0xBB
                              #define DISCTL 0xCA
                              #define PASET 0x75
                              #define CASET 0x15
                              #define DATCTL 0xBC
                              #define RGBSET8 0xCE
                              #define RAMWR 0x5C
                              #define RAMRD 0x5D
                              #define PTLIN 0xA8
                              #define PTLOUT 0xA9
                              #define RMWIN 0xE0
                              #define RMWOUT 0xEE
                              #define ASCSET 0xAA
                              #define SCSTART 0xAB
                              #define OSCON 0xD1
                              #define OSCOFF 0xD2
                              #define PWRCTR 0x20
                              #define VOLCTR 0x81
                              #define VOLUP 0xD6
                              #define VOLDOWN 0xD7
                              #define TMPGRD 0x82
                              #define EPCTIN 0xCD
                              #define EPCOUT 0xCC
                              #define EPMWR 0xFC
                              #define EPMRD 0xFD
                              #define EPSRRD1 0x7C
                              #define EPSRRD2 0x7D
                              #define NOP 0x25
                              Mạch nạp Little Programmer
                              MSC-51,AVR,EEPROM ... etc

                              Site Fukusei shop :

                              Comment


                              • À chú ý trên thị trường hiện có xuất hiện nhìu màn hình giống nhau . Các bạn mua nên chú ý loại philip hiện trong sài gòn còn tất ít điểm bán . Mình củng đang làm một cái module LCD như thằng sparkfun không hoàn toàn giống như vậy . Mình đang test thừ và đã chạy tốt nhưng mình muốn thử lại cho thiệt kỹ trước như bán ra .
                                Mạch nạp Little Programmer
                                MSC-51,AVR,EEPROM ... etc

                                Site Fukusei shop :

                                Comment

                                Về tác giả

                                Collapse

                                emdaikho Tìm hiểu thêm về emdaikho

                                Bài viết mới nhất

                                Collapse

                                Đang tải...
                                X