|
大家好!断断续续研究5509DSP快一年了可是还是一个脑袋两个大,请教大侠个解释一下这个程序;还有对于5509DSP应该怎么学,
/*********************************************************************
** Module Name: 1602 LCD **
** Author: CTH **
** Version: 1.0 **
** CreateDate: 2008-8-10 **
** Description: **
** Remark: **
** Revision History: 2008-8-10 **
** Web: http://www.study-kit.com **
**********************************************************************/
/*********************************************************************
** 实验目的:了解1602字符液晶的使用功能 **
** 实验说明:数据线是和12864液晶共用在一起的,都是从CPLD引出来的,控 **
** 制信号RS和E两个信号线全部都是由CPLD引出的.因此在CPLD中 **
** 将会定义他们各自的地址.具体还得看我们提供的手册来学习 **
** 实验结果:显示两行字符,开发板之家的网址和电话。 **
**********************************************************************/
#include <csl.h>
#include <csl_pll.h>
#include <csl_emif.h>
#include <csl_chip.h>
#include <stdio.h>
#define led8 (*((unsigned int *)0x200001)) //这里的*((unsigned int *)0x200001)是什么,数字干什么用啊,怎么知道
#define Digital8 (*((unsigned int *)0x200002))
#define LCD_REG (*((unsigned int *)0x200003))
#define buzzer (*((unsigned int *)0x200004))
#define USER_SW (*((unsigned int *)0x200005))
#define LCD_DATA (*((unsigned int *)0x200006))
#define UART_BASE_ADDR 0x200008
#define RBR *((int *)(UART_BASE_ADDR+0))
#define THR *((int *)(UART_BASE_ADDR+0))
#define IER *((int *)(UART_BASE_ADDR+1))
#define IIR *((int *)(UART_BASE_ADDR+2))
#define FCR *((int *)(UART_BASE_ADDR+2))
#define LCR *((int *)(UART_BASE_ADDR+3))
#define MCR *((int *)(UART_BASE_ADDR+4))
#define LSR *((int *)(UART_BASE_ADDR+5))
#define MSR *((int *)(UART_BASE_ADDR+6))
#define SCR *((int *)(UART_BASE_ADDR+7))
#define DLL *((int *)(UART_BASE_ADDR+0))
#define DLM *((int *)(UART_BASE_ADDR+1))
#define comm 0
#define dat 1
/*要显示的字符*/
unsigned char str1[]={"TianjinPolytechnicUniversity"};
unsigned char str2[]={"No. 63 Chenglin Road,Hedong District,Tianjin 300160, P. R. of China"};
void Delay(unsigned int nDelay);
void wr_lcd(unsigned char dat_comm, unsigned int content);
void delaynum(unsigned int d_time);
/*锁相环的设置*/
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
12, //PLL multiply value; multiply 12 times
2 //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)
};
/*SDRAM的EMIF设置*/
EMIF_Config emiffig = {
0x221, //EGCR : the MEMFREQ = 00,the clock for the memory is equal to cpu frequence
// the WPE = 0 ,forbiden the writing posting when we debug the EMIF
// the MEMCEN = 1,the memory clock is reflected on the CLKMEM pin
// the NOHOLD = 1,HOLD requests are not recognized by the EMIF
0xFFFF, //EMI_RST: any write to this register resets the EMIF state machine
0x1fff, //CE3_1: CE0 space control register 1
0x00ff, //CE3_2: CE0 space control register 2
0x00ff, //CE3_3: CE0 space control register 3
0x1fff, //CE1_1: CE0 space control register 1
// Asynchronous, 16Bit
0x00ff, //CE1_2: CE0 space control register 2
0x00ff, //CE1_3: CE0 space control register 3
0x1FFF, //CE2_1: CE0 space control register 1
// Asynchronous, 16Bit
0xFFFF, //CE2_2: CE0 space control register 2
0x00FF, //CE2_3: CE0 space control register 3
0x1fff, //CE3_1: CE0 space control register 1
0x00ff, //CE3_2: CE0 space control register 2
0x00ff, //CE3_3: CE0 space control register 3
0x2911, //SDC1: SDRAM control register 1
// TRC = 8
// SDSIZE = 0;SDWID = 0
// RFEN = 1
// TRCD = 2
// TRP = 2
0x0410, //SDPER : SDRAM period register
// 7ns *4096
0x07FF, //SDINIT: SDRAM initialization register
// any write to this register to init the all CE spaces,
// do it after hardware reset or power up the C55x device
0x0131 //SDC2: SDRAM control register 2
// SDACC = 0;
// TMRD = 01;
// TRAS = 0101;
// TACTV2ACTV = 0001;
};
/*************以下内容为LCD的读写等函数**************/
/* 参考:LCD说明书
TMS320VC5509 DSP External Memory Interface (EMIF) Reference Guide
*/
//*addr为CPLD寄存器操作专用指针
void delay(unsigned int d_time)
{
while(d_time--);
}
main()
{
int k;
/*初始化CSL库*/
CSL_init();
/*EMIF为全EMIF接口*/
CHIP_RSET(XBSR,0x0a01);
/*设置系统的运行速度为144MHz*/
PLL_config(&myConfig);
/*初始化DSP的EMIF*/
EMIF_config(&emiffig);
wr_lcd(comm,0x01); //清屏指令
wr_lcd(comm,0x38); //设定LCD为16*2,5*7矩阵,8位数据接口
wr_lcd(comm,0x0f); //显示ON 光标ON,闪烁ON
wr_lcd(comm,0x06); //文字不动,光标
while(1)
{
wr_lcd(comm,0x80); //第一行字符地址
for(k=0;k<16;k++)
{
wr_lcd(dat,str1[k]);
delay(200);
}
wr_lcd(comm,0xc0); //第二行数据指针的地址
for(k=0;k<16;k++)
{
wr_lcd(dat,str2[k]);
delay(200);
}
delay(10000);
}
//LCD输出设置
}
void delaynum(unsigned int d_time)
{
while(d_time--);
}
// BIT 0 LCD1602 RS
// BIT 1 LCD1602 EN
void wr_lcd(unsigned char dat_comm, unsigned int content)
{
//EN 高变低电平,液晶开始操作
//RS 高电平为数据寄存器 低电平为指令寄存器
Delay(40);
if(dat_comm)
{
LCD_REG=0x01;
LCD_DATA=content; //数据端口
LCD_REG=0x03; //en=0
delaynum(80);
LCD_REG=0x00; //en=0
}
else
{
LCD_REG=0x00;
LCD_DATA=content;
LCD_REG=0x02; //rs==1 en==0 写指令端口
delaynum(80);
LCD_REG=0x00; //en=0
}
Delay(100);
}
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}
/******************************************************************************\
* End of lcd.c
\******************************************************************************/ |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|