RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

LCD 5510 và atmega16

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • voiviqua
    Thành viên tích cực
    • Jan 2011
    • 141

    #1

    LCD 5510 và atmega16

    có anh nào đã làm được giao tiếp atmega16 với LCD nokia 5510 chưa vậy.cho em xin code với.em đang làm nó mà nó không chạy.
    code của em.
    #include <mega16.h>
    #include <delay.h>
    //#define DC PORTC.1;
    //#define RESET PORTC.2;
    //#define CS PORTC.3;
    // SPI functions
    #include <spi.h>

    // Declare your global variables here
    void spi_gui(unsigned char data)
    {
    PORTC.3=1;
    delay_us(10);
    PORTC.3=0;
    SPDR=data;
    while((SPSR & 0x80)==0);
    PORTC.3=1;
    }
    void LCDWrite(char data_or_command, unsigned char data1)
    {
    if(data_or_command==0) PORTC.1=0;
    else PORTC.1=1;
    PORTC.3=0;
    spi_gui(data1); // Send the data
    PORTC.3=1;
    }

    void gotoXY(int x, int y)
    {
    LCDWrite(0, 0x80 | x); // Column.
    LCDWrite(0, 0x40 | y); // Row.
    }

    void LCDClear() //Clears the LCD by writing zeros to the entire screen
    {
    unsigned int i;
    for (i = 0 ; i < 504 ; i++) LCDWrite(1, 0x00);
    gotoXY(0, 0); //After we clear the display, return to the home position
    }

    void LCDInit(unsigned char contrast,unsigned char coefficent,unsigned char bias) //This sends the magical commands to the PCD8544
    {
    PORTC.2=1; PORTC.3=1; PORTC.1=1; //Configure control pins
    PORTC.2=0; //Reset the LCD to a known state
    PORTC.2=1;
    LCDWrite(0, 0x21); //Tell LCD that extended commands follow
    LCDWrite(0, 0x80 + contrast); //Set contrast (max 127);
    LCDWrite(0, 0x04 + coefficent); //Set Temp coefficent (max 4);
    LCDWrite(0, 0x10 + bias); //LCD bias mode (max 15);
    LCDWrite(0, 0x20); //We must send 0x20 before modifying the display control mode
    LCDWrite(0, 0x0C); //Set display control, normal mode. 0x0D for inverse
    }

    void main(void)
    {
    // Declare your local variables here

    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    PORTA=0xff;
    DDRA=0xff;

    // Port B initialization
    // Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
    // State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
    PORTB=0x00;
    DDRB=0xB0;

    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    PORTC=0x00;
    DDRC=0xff;

    // Port D initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    PORTD=0xff;
    DDRD=0xff;


    // SPI initialization
    // SPI Type: Master
    // SPI Clock Rate: 2000.000 kHz
    // SPI Clock Phase: Cycle Half
    // SPI Clock Polarity: Low
    // SPI Data Order: MSB First
    SPCR=0x50;
    SPSR=0x00;
    LCDInit(1,0,0);
    LCDClear();
    while (1)
    {
    // Place your code here
    gotoXY(1,2);
    LCDWrite(1,0x55);
    delay_ms(10000);
    };
    }


    các anh xem hộ em xem nó sai ở đâu mà em làm mãi nó không chạy được gì cả.
  • chung1608
    Thành viên tích cực
    • Sep 2009
    • 4160

    #2
    thử viết bằng SPI mềm đi

    Comment

    • voiviqua
      Thành viên tích cực
      • Jan 2011
      • 141

      #3
      Nguyên văn bởi chung1608 Xem bài viết
      thử viết bằng SPI mềm đi
      anh nói rõ hơn đi.viết bằng SPI mềm là thế nào a.

      Comment

      • voiviqua
        Thành viên tích cực
        • Jan 2011
        • 141

        #4
        Nguyên văn bởi chung1608 Xem bài viết
        thử viết bằng SPI mềm đi
        anh nói rõ hơn đi.viết bằng SPI mềm là thế nào a.

        Comment

        • voiviqua
          Thành viên tích cực
          • Jan 2011
          • 141

          #5
          sao không ai giúp em vậy.

          Comment

          • chung1608
            Thành viên tích cực
            • Sep 2009
            • 4160

            #6
            SPI mềm là tự viết SPI bằng code, mình cũng từng làm với 1100 rồi nhưng dùng SPI cứng vẫn ko chạy.
            Code:
             void lcd_write(char MODE,unsigned char c)
             {
             char i;
             cs = 0;
             sclk = 0;
             sda = MODE;
             sclk = 1;
             for(i=0;i<8;i++)
             {
             sclk = 0;
             if(c & 0x80) sda = 1;
             else sda = 0;
             sclk = 1;
             c <<= 1;
             }
             cs = 1;
             }

            Comment

            • voiviqua
              Thành viên tích cực
              • Jan 2011
              • 141

              #7
              cảm ơn bạn nhé.mình làm được rồi.

              Comment

              Về tác giả

              Collapse

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

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

              Collapse

              Đang tải...