我用的是MSP430F2013芯片,不知道什么大原因,就是点不亮,好郁闷啊。
代码如下:
#include "msp430x20x3.h"
#include "intrinsics.h"
#include "config.h"
#define BIAS 0x52
#define SYSEN 0x02
#define LCDON 0x06
#define LCDOFF 0x04
#define RC256K 0x30
#define WTDDIS1 0x0a
#define SYSDIS 0X00
#define CS_L P1OUT &= ~BIT2
#define CS_H P1OUT |= BIT2
#define WR_L P1OUT &= ~BIT3
#define WR_H P1OUT |= BIT3
#define DAT_L P1OUT &= ~BIT4
#define DAT_H P1OUT |= BIT4
unsigned char table[]={0x5f,0x06,0x6b,0x1f,0x36,0x3d,0x7d,0x07,0x7f,0x3f};
void delay(unsigned char b)
{
unsigned char i;
while(b--)
for(i=0;i<65;i++);
}
/*从高位开始按位写入HT1621,高位开始写地址用*/
void SendBitAddr_1621(unsigned char data,unsigned char cnt)
{
unsigned char i;
for(i=0;i<cnt;i++)
{
WR_L;
delay(4);
if((data&0x80)==0)
DAT_L;
else
DAT_H;
delay(4);
WR_H;
delay(4);
data<<=1;
}
}
/*从低位开始按位写入HT1621,低位开始写数据用*/
void SendBitData_1621(unsigned char data,unsigned char cnt)
{
unsigned char i;
for(i=0;i<cnt;i++)
{
WR_L;
delay(4);
if((data&0x01)==0)
DAT_L;
else
DAT_H;
delay(4);
WR_H;
delay(4);
data>>=1;
}
}
/*发送命令至HT1621*/
void SendCmd(unsigned char command)
{
CS_L;
SendBitAddr_1621(0x80,4);
SendBitData_1621(command,8);
CS_H;
delay(4);
}
/*写1621地址6位,数据4位*/
void Write_1621(unsigned char addr,unsigned char data)
{
CS_L;
SendBitAddr_1621(0xa0,3);//发送指令101
SendBitAddr_1621(addr,6);//地址高6位
SendBitData_1621(data,4);//数据低4位
CS_H;
delay(4);
}
/*写1621地址6位,数据8位*/
void Write_1621_8(unsigned char addr,unsigned char data)
{
CS_L;
SendBitAddr_1621(0xa0,3);//发送指令101
SendBitAddr_1621(addr,6);//地址高6位
SendBitData_1621(data,8);//数据低8位
CS_H;
delay(4);
}
/*连续写*/
void Write_All_1621(unsigned char addr,unsigned char *p,unsigned char cnt)
{
unsigned char i;
CS_L;
SendBitAddr_1621(0xa0,3);
SendBitAddr_1621(addr,6);
for(i=0;i<cnt;i++)
{
SendBitData_1621(*p,8);
p++;
}
CS_H;
delay(4);
}
/*初始化函数*/
void init_1621()
{
P1DIR |= BIT4+BIT3+BIT2;
P1DIR &=~(BIT0+BIT1+BIT5+BIT6+BIT7);
CS_H;
WR_H;
DAT_H;
SendCmd(BIAS);
SendCmd(RC256K);
SendCmd(SYSDIS);
SendCmd(WTDDIS1);
SendCmd(SYSEN);
SendCmd(LCDON);
}
void main( void )
{
// int i,k;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
if (CALBC1_8MHZ==0xFF) // If calibration constants erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation
/*
if (CALBC1_1MHZ==0xFF) // If calibration constants erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; */
delay(50);
BCSCTL2 |= DIVM_3+SELM_0;
init_1621();
delay(10);
Write_1621(0x01,0x04);
Write_All_1621(0,table,10);
while(1)
{
}
} |