我用的是MSP430FG4619,连接的LCD是NHD‐C12832A1Z‐NSW‐BBW‐3V3
用SPI,我查了有3pin和4pin模式, 我的这个连接用了SCL, STE, SIMO,SOMI没有连,不知道是3pin还是4pin
初始化还是有困难,请大家帮帮忙
以下是LCD datasheet上提供的sample code
void data_out(unsigned char i) //Data Output Serial Interface
{
unsigned int n;
CS = 0;
A0 = 1;
for(n=0; n<8; n++){
i <<=1;
SCL = 0;
P1 = i;
delay(2);
SCL = 1;
}
CS = 1;
}
void comm_out(unsigned char j) //Command Output Serial Interface
{
unsigned int n;
CS = 0;
A0 = 0;
for(n=0; n<8; n++){
j <<=1;
SCL = 0;
P1 = j;
delay(2);
SCL = 1;
}
CS = 1;
}
/****************************************************
* Initialization For controller *
*****************************************************/
void init_LCD()
{
comm_out(0xA0);
comm_out(0xAE);
comm_out(0xC0);
comm_out(0xA2);
comm_out(0x2F);
comm_out(0x26);
comm_out(0x81);
comm_out(0x2F);
}
/*****************************************************/
此帖出自
小平头技术问答
#include <msp430xg46x.h>
#include "pic.h"
/* For USI, these are the required pin assignments:
* P7.0 CS -- Chip Select .
* P7.1 SDO -- serial data out (MOSI for master)
* P7.3 SCL -- serial clock
* P7.4 A0 -- Command/Data .
* p7.5 RESET
*/
#define LCD_D P7SEL |= 0x01 // Chip Select line
#define LCD_E P7SEL &=~0x01
#define Data_out P7OUT |= 0x10 // Command/Data mode line
#define Com_out P7OUT &=~0x10
#define RST_E P7OUT |=0x20
#define RST_C P7OUT &=~0x20
unsigned char data[]; int bytes;
void init_LCD(void);
void dispPic();
void main( void )
{
volatile unsigned int i;
// Stop the watchdog timer so it doesn't reset our chip
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= XCAP14PF; // Configure load caps
// DCO to stabilize.
__delay_cycles( 1000 );
P7SEL |= 0x0B; // P7.1,3 option select
P7SEL &=~0x30;
P7DIR |=0x30; // P7.0,4,5
P7OUT |=0x30;
UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB+UCMODE_2; //4-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 2; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
// Pause so everything has time to start up properly.
__delay_cycles( 5500 );
// Initialize the LCD panel.
init_LCD();
while(1)
{ //loop forever
dispPic(logo); //show image
__delay_cycles(1000); //wait 1s
dispPic(graphic1);
__delay_cycles(1000);
dispPic(graphic2);
__delay_cycles(1000);
}//_BIS_SR(LPM0_bits + GIE); // CPU off, enable interrupts
}
void spi_IO( unsigned char data[], int bytes )
{
int n=0;
// Set Chip Select low, so LCD panel knows we are talking to it.
LCD_E;
while(n < bytes)
{
UCA0TXBUF = data[n]; // load byte into transmit buffer
__delay_cycles( 100 );
n++;
}
//IE2 &= ~UCA0TXIE;
// Set Chip Select back high to finish the communication.
LCD_D;
}
/****************************************************
* Initialization For controller *
*****************************************************/
void init_LCD()
{
RST_E;
__delay_cycles( 50 );
RST_C;
__delay_cycles( 50 );
RST_E;
__delay_cycles( 50 );
unsigned char init_data[]=
{
0xA0,0xAE,0xC0,0xA2,0x2F,0x26,0x81,0x2F
};
Com_out; // set for commands
spi_IO( init_data, sizeof(init_data));
Data_out;
}
void dispPic(unsigned char *lcd_string)
{
unsigned int i,j;
unsigned char page = 0xB0; //Page Address + 0xB0
LCD_E;
Com_out;
UCA0TXBUF=0xAE; //Display OFF
UCA0TXBUF=0x40; //Display start address + 0x40
for(i=0;i<4;i++)
{ //32pixel display / 8 pixels per page = 4 pages
Com_out;
UCA0TXBUF=page; //send page address
UCA0TXBUF=0x10; //column address upper 4 bits + 0x10
UCA0TXBUF=0x00; //column address lower 4 bits + 0x00
Data_out;
for(j=0;j<128;j++)
{ //128 columns wide
UCA0TXBUF=*lcd_string; //send picture data
lcd_string++; //point to next picture data
__delay_cycles( 50 );
}
page++; //after 128 columns, go to next page
}
Com_out;
UCA0TXBUF=0xAF; //Display ON
Data_out;
LCD_D;
}
一周热门 更多>