Thông báo

Collapse
No announcement yet.

help me!!!!! LCD TC1602A

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

  • #16
    Địa chỉ mail của em diachiwebhoc@gmail.com

    Comment


    • #17
      #include <REGX51.H>
      #include<string.h>
      sfr LCD_data=0xa0;
      sbit BF=0xa7;
      sbit RS=P3^5;
      sbit Rw=P3^4;
      sbit En=P3^3;
      void wait(void)
      {
      long n=0;
      En=1;
      RS=0;
      Rw=1;
      LCD_data=0Xff;
      while(BF){n++;if(n>100) break;}
      En=0;
      Rw=0;
      }
      //*ham dieu khien LCD thuc hien 1 lenh*//
      void LCD_control(unsigned char x)
      {
      En=1;
      RS=0;
      Rw=0;
      LCD_data=x;
      En=0;
      wait();
      }
      //*ham khoi tao

      void LCDinit(void)
      {
      LCD_control(0x30);//che do 8 bit
      LCD_control(0X38);//2 dong va ma tran 5X7
      LCD_control(0x0C);//bat contro
      LCD_control(0x06);//tang con troi dich con tro sang phai
      LCD_control(0x01);//xoa man hinh
      }
      //============
      void LCD_write(unsigned char c)
      {
      En=1;
      RS=1;
      Rw=0;
      LCD_data=c;
      En=0;
      wait();
      }
      //=========
      void LCD_puts(unsigned char *s,unsigned char row)
      {
      unsigned char len;
      if(row==1) LCD_control(0x80) ;
      else LCD_control(0xc0);
      len=strlen(s);
      While(len!=0)
      {
      LCD_write(*s);
      s++;
      len--;

      }
      }
      //=================
      void delay(long time)
      (
      long n;
      for(n=0;n<time;n++)
      {
      ;
      };
      )
      //=============
      void main(void)
      {
      char x;
      LCDinit();
      LCD_puts("8052mcu",1);
      delay*(30000);
      While(1==1)
      {
      for(x=0;x<15;x++)
      {
      LCD_puts("8052mcu",1);
      LCD_control(0X18) ;
      delay(5000)
      }
      }
      }
      anh em giúp tôi với tại sao chương trình thế này mà không chạy được hic hic .Minh dùng trình dịch KEILC nó cứ báo lỗi mãi .Giúp mình với hic hic
      |

      Comment


      • #18
        Giao tiếp LCD 16x2 dùng Keil-C đã có sẵn file .h này rồi. Đơn giản và dễ hiểu. Bác cứ lấy dùng, đừng cố gắng tạo nữa chỉ mất công mà chạy không ổn định.

        Các hàm em bôi xanh là các hàm bác cần quan tâm. Còn lại là gì thì kệ xác nó. Hì hì. Chắc chắn chạy !

        /************************************************** **************************/
        // define Hardware address
        /************************************************** ***************************/
        #define LCD_PORT P1 //<-- cái này tùy bác
        sbit LCD_RS = LCD_PORT^0;
        sbit LCD_RW = LCD_PORT^1;
        sbit LCD_EN = LCD_PORT^2;
        sbit LCD_BG = LCD_PORT^3; //cái này em chọn để tắt mở background led bằng 89 luôn.

        #define ReadCommand {LCD_RS = 0; LCD_RW = 1;}
        #define WriteCommand {LCD_RS = 0; LCD_RW = 0;}
        #define WriteData {LCD_RS = 1; LCD_RW = 0;}
        #define LatchData {LCD_EN = 1; LCD_EN = 0;}

        /************************************************** **************************
        define LCD command
        ************************************************** ***************************/
        #define LCD_CLEAR 0x01 // Clear display
        #define LCD_HOME 0x02 // return cursor and LCD to home position
        #define LCD_OFF 0x08 // turn off display and cursor
        #define LCD_DISPLAY_ON 0x0C // turn on display and turn off cursor
        #define LCD_CURSOR_ON 0x0A // turn on cursor and turn off display
        #define LCD_BLINK_CURSOR 0x0E // turn on display and blink cursor
        #define LCD_FONT_8BIT 0x38 // set interace length: 8bits, 2 lines, font 5x8
        #define LCD_FONT_4BIT 0x28 // set interace length: 4bits, 2 lines, font 5x8
        #define LCD_MOVE_CURSOR 0x06 // Entry mode set: set increments mode, not shift (cursor)
        #define LCD_MDRIGHT 0x1C // Move display to the right
        #define LCD_MDLEFT 0x18 // Move display to the left

        //================================================== ============
        void LCD_BgON(void)
        {
        LCD_BG = 0;
        }
        //================================================== ============
        void LCD_BgOFF(void)
        {
        LCD_BG = 1;

        }
        //================================================== ===============
        void WaitReady()
        {
        bit lcd_busy = 1;
        ReadCommand;
        LCD_PORT |= 0xF0; // set outputlatches to '1'
        while(lcd_busy){
        LCD_EN = 1; // read high nibble
        lcd_busy = 1;
        lcd_busy = LCD_PORT & 0x80; // return bit 7
        LCD_EN = 0;
        LCD_EN = 1; // read low nibble
        LCD_EN = 0;
        }
        }

        //================================================== ============================
        void write_char(unsigned char c)
        {
        unsigned char temp;
        temp = c & 0xF0; // Don't affect bits 0-3
        LCD_PORT &= 0x0F; // Bits 4..7 <- 0
        LCD_PORT |= temp; // High nibble to display
        LatchData;

        temp = (c << 4) & 0xF0; // Prepare to send low nibble
        LCD_PORT &= 0x0F; // Bits 4..7 <- 0
        LCD_PORT |= temp; // Low nibble to display
        LatchData;
        }

        /************************************************** ***************************/
        void LCD_Init_Write(unsigned char cmd)
        {
        WaitReady();
        WriteCommand;
        LCD_PORT = cmd;
        LatchData;
        }

        /************************************************** **************************
        LCD_PutCmd function
        Write a control byte to LCD
        Input : control byte
        ************************************************** ***************************/
        void LCD_PutCmd(unsigned char cmd)
        {
        WaitReady(); // Wait for LCD ready
        WriteCommand; // set LCD to send mode
        write_char(cmd); // send command
        }

        /************************************************** **************************
        LCD_PutChar function
        Write a ASCII symbol to LCD
        Input: ASCII symbol
        ************************************************** ***************************/
        void LCD_PutChar(unsigned char ch)
        {
        WaitReady();
        WriteData;
        write_char(ch);
        }

        /************************************************** ***************************
        LCD_PrString function
        Write a string to LCD
        Input: string
        ************************************************** ****************************/
        void LCD_PutStr(char *str)
        {
        while(*str!='\0'){
        LCD_PutChar(*str);
        ++str;
        }
        }

        /************************************************** ***************************
        LCD_Position function
        Set the position of cursor on LCD
        Input: row, column
        ************************************************** ****************************/
        void LCD_Pos(unsigned char row, unsigned char col)
        {
        LCD_PutCmd( (1<<7)|(row<<6)|col );
        }

        /************************************************** ***************************
        LCD_Clear function
        Clear LCD
        ************************************************** ****************************/
        void LCD_Clear()
        {
        LCD_PutCmd(LCD_CLEAR);
        }

        /************************************************** ***************************
        LCD_Init function
        Prepare for display content. Must be called at first
        ************************************************** ****************************/
        void LCD_Init()
        {

        LCD_Init_Write(LCD_FONT_4BIT); // 0x28 set a 5x8 dot character font
        LCD_PutCmd(LCD_FONT_4BIT); // and 4 bits data bus
        LCD_PutCmd(LCD_OFF);
        // LCD_Clear();
        LCD_PutCmd(LCD_DISPLAY_ON); // 0x0C, Display on and cursor off
        LCD_PutCmd(LCD_MOVE_CURSOR); // 0x06
        // LCD_PutCmd(LCD_BLINK_CURSOR); // Blink cursor
        }

        /************************************************** **************************
        LCD_PrInteger function
        Display a integer decimal number to LCD
        Input: a integer number
        ************************************************** ***************************/
        void LCD_PutNum(int num)
        {
        int temp;
        unsigned char i = 0, c[5];
        temp = num;
        if (temp != 0) {
        if (temp < 0){
        LCD_PutChar('-');
        temp = - temp;
        }
        while(temp){
        c[i++] = temp%10;
        temp /= 10;
        }
        while(i) LCD_PutChar(c[--i] + '0');
        }
        else LCD_PutChar('0');
        }

        Comment


        • #19
          muốn cho chữ chạy có cần xóa đi xóa lại màn hình không hả các bác
          mà em thấy trong cái hàm LCD_PutNum() có lệnh:

          while(i) LCD_PutChar(c[--i] + '0');

          biến truyền vào hàm này là char cơ mà, lệnh trên vẫn dịch và chạy bình thường ,em vẫn chưa hiểu tại sao lại thê, tại sao lại phải thêm kí tự '0' vào cuối trước khi đưa lên LCD

          Comment


          • #20
            minh co so do nguyen ly cua mach dem san pham nay .xin cac su huynh gop y. su huynh nao co the lap trinh thi giup voi.
            Attached Files

            Comment

            Về tác giả

            Collapse

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

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

            Collapse

            Đang tải...
            X