代码:
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_gpio.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define Smg_a 0x80
#define Smg_b 0x40
#define Smg_c 0x20
#define Smg_d 0x01
#define Smg_e 0x02
#define Smg_f 0x08
#define Smg_g 0x04
#define Smg_dp 0x10
#define Bmp0Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f
#define Bmp1Map Smg_b | Smg_c
#define Bmp2Map Smg_a | Smg_b | Smg_d | Smg_e | Smg_g
#define Bmp3Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_g
#define Bmp4Map Smg_b | Smg_c | Smg_f | Smg_g
#define Bmp5Map Smg_a | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp6Map Smg_a | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp8Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp9Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp7Map Smg_a | Smg_b | Smg_c
#define BmpAMap Smg_a | Smg_b | Smg_c | Smg_e | Smg_f | Smg_g
#define BmpBMap Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpCMap Smg_a | Smg_d | Smg_e | Smg_f
#define BmpDMap Smg_b | Smg_c | Smg_d | Smg_e | Smg_g
#define BmpEMap Smg_a | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpFMap Smg_a | Smg_e | Smg_f | Smg_g
unsigned char temp=0;
#define CS_0 GPIO_RSET(IODATA,temp&0x0fe)
#define CS_1 GPIO_RSET(IODATA,temp|0X001)
#define WR_0 GPIO_RSET(IODATA,temp&0x0fd)
#define WR_1 GPIO_RSET(IODATA,temp|0X002)
#define DA_0 GPIO_RSET(IODATA,temp&0x0fb)
#define DA_1 GPIO_RSET(IODATA,temp|0X004)
const unsigned char SegCode[] = {Bmp0Map,Bmp1Map,Bmp2Map,Bmp3Map,Bmp4Map,Bmp5Map,
Bmp6Map,Bmp7Map,Bmp8Map,Bmp9Map,BmpAMap,BmpBMap,
BmpCMap,BmpDMap,BmpEMap,BmpFMap};
unsigned char DpyNum[6] = {Smg_g,Smg_g,Smg_g,Smg_g,Smg_g,Smg_g}; //显示缓冲区
unsigned int i;
void delay(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<20;j++);
}
void COMMAND_HT1621(unsigned char comm)
{
unsigned char i;
CS_0;
delay(5);
WR_0;
delay(5);
for(i=0;i<3;i++) //写命令
{
if((0x04<<i)&0x04) DA_1; //100
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<9;i++) //写命令数据
{
if((comm<<i)&0x80) DA_1; //100
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
CS_1;
delay(5);
}
void HT1621_Display(void)
{
unsigned char i;
CS_0; //片选CS
delay(5);
WR_0;
delay(5);
for(i=0;i<3;i++) //写命令
{
if((0x05<<i)&0x04) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<6;i++) //写地址
{
if((20<<i)&0x20) DA_1; //20对应 SEG地址
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[5]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[4]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[3]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[2]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[1]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[0]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
CS_1; //释放CS
delay(5);
}
void LCD_Init(void)
{
COMMAND_HT1621(0x01); //SYS EN
COMMAND_HT1621(0x03); //LCD ON
COMMAND_HT1621(0x29); //4 COM 1/3 BIAS
HT1621_Display(); //clear screen
}
void delay1();
/*锁相环的设置*/
PLL_Config myConfig = {
0, //IAI: the PLL locks using the same process that was underway
//before the idle mode was entered
1, //IOB: If the PLL indicates a break in the phase lock,
//it switches to its bypass mode and restarts the PLL phase-locking
//sequence
24, //PLL multiply value; multiply 24 times
1 //Divide by 2 PLL divide value; it can be either PLL divide value
//(when PLL is enabled), or Bypass-mode divide value
//(PLL in bypass mode, if PLL multiply value is set to 1)
};
main()
{
/*初始化CSL库*/
CSL_init();
/*设置系统的运行速度为144MHz*/
PLL_config(&myConfig);
/*确定方向为输出*/
GPIO_RSET(IODIR,0xFF);
LCD_Init();
DpyNum[0] = SegCode[0]; //"三"
DpyNum[1] = SegCode[3];
DpyNum[2] = SegCode[6];
DpyNum[3] = SegCode[9];
DpyNum[4] = SegCode[12];
DpyNum[5] = SegCode[15];
HT1621_Display();
while(1)
{
}
}
void delay1()
{
Uint32 j = 0,k = 0;
for(j = 0;j<0x30;j++)
{
for(k= 0;k<0xffff;k++)
{}
}
}
/******************************************************************************\
* End of gpio.c
\******************************************************************************/
我试图用TMS320VC5509A驱动HT1621,可是不成功。
#define CS_0 GPIO_RSET(IODATA,temp&0x0fe)
#define CS_1 GPIO_RSET(IODATA,temp|0X001)
#define WR_0 GPIO_RSET(IODATA,temp&0x0fd)
#define WR_1 GPIO_RSET(IODATA,temp|0X002)
#define DA_0 GPIO_RSET(IODATA,temp&0x0fb)
#define DA_1 GPIO_RSET(IODATA,temp|0X004)
我担心是这几句有问题。
不知道5509有没有对IO口位操作的函数。
请大神指教,谢谢!
|