首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

mc9s08控制ht1621b,碰到问题请教,附程序

mc9s08控制ht1621b,碰到问题请教,附程序

mc9s08qg4控制ht1621b,可我怎么都点不亮lcd,使用过ht1621的高手帮帮忙!程序如下:
ht1621.c:
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
//#include

#define WR 0B00001000 //时钟线
#define DATA 0B00000100 //数据线
#define CS 0B00000010 //片选线
#define P 0x80
#define data_length 8
#define LCD_ON 0x06
#define LCD_OFF 0x04
const char seg_tab[10]={0x7d,0x60,0x3e,0x7a,0x63,0x5b,0x5f,0x70,0x7f,0x7b}; //时钟0~8

const char seg_tab1[10]={0x5f,0x06,0x6b,0x2f,0x36,0x3d,0x7d,0x07,0x7f,0x3f};

unsigned char disbuff[4] ={0,0,0,0}; //对应LCD时钟4位

unsigned long int time =0; //每一毫秒加1
//1621的显存是4位*32的,故用16*8位的寄存器就能满足要求奇数显存放高4位,偶数放低4位
/*****************************************************************/
//1621初始化命令
const char init_tab[]={
0x52, // 1/3duty 4com bias
0x00, //关振系统荡器和LCD偏压发生器
0x06, //打开LCD偏压
0x02, //打开系统振荡器
0x30, //内部时钟
0x10, //关闭声音输出
0x0a, //禁止看门狗
0x80 //禁止IRQ 输出有效命令
};


void send_data(unsigned char data_bus,unsigned char loop);
void delayns(void);
void display(void);
void display_init(void);
void votlageget(void);
void delay(int temp);

//***********************************************************************/
void display_init(void)
{
unsigned char t;
PTAD &=~CS;
//send_data(0b10000000,3); //送3位命令模式代码100
send_data(0b10000000,4);
for(t=0;t<=7;t++)
{
send_data(init_tab[t],8); //送9位命令代码
}
PTAD |=CS;
PTAD |=WR;
}

//***********************************************************************/
void display(void)
{
unsigned char t;
unsigned char seg_temp;

PTAD &=~CS;
PTAD &=~WR;
send_data(0b10100000,3); //送3位“写 ”模式命令代码101
send_data(0,6); //送6位首地址00h
for(t=0;t<=3;t++)
{
seg_temp =seg_tab[disbuff[t]];

send_data(seg_temp,data_length); //向显存送数据
}
PTAD |=CS;
PTAD |=WR;
}

//***********************************************************************/

void send_data(unsigned char data_temp,unsigned char loop)
{
for(;loop!=0;loop--)
{
delayns();
PTAD &=~WR;
delayns();
if((data_temp&0x80)==0)
{
PTAD &=~DATA;
}
else
{
PTAD |=DATA;
}
data_temp=(data_temp<<1);
PTAD |=WR;
}
}
//~~~~~~~~~~~~~~~~~~~~~`
void delayns(void)
{

asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
下面是主函数,中断刷新lcd
main.c
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "ds1302.h"
uchar count= 20,jishu;
unsigned char disbuf[4] ={0,0,0,0};

unsigned long int time1 =0;
void display_init(void);
void display(void);
void send_data(unsigned char data_bus,unsigned char loop);

void InitIcs(void)
{
//ICSC1=0x04; /* CLKS for Internal reference clock, IREFS for internal reference */
//ICSC2=0x08; /* BDIV divide by 1, LP for FLL disabled */
//ICSTRM=0x00; //内部振荡器调整因子
//ICSSC =0x00;
}

void InitSys(void)
{
// SOPT:
SOPT1 = 0x03; // COPE=0,COPT=0,STOPE=0 ,BKGDPE=1,RSTPE=1;
SOPT2 = 0x80; //COPCLKS =1:INTERNAL 1KCLK IS SOURCE TO COP
//SDIDL = 0x09;
//SPMSC1 = 0x1c; //system power managememt status and control
//SPMSC2 = 0x00;
}

void InitPort(void)
{

PTADD=0xff; // 1100 1000
PTAD= 0xff; // 1111 0111
//PTAPE=0x07; // Internal Pullup Enable
//PTASE=0x3f; // Output Slew Rate Control Enable
//PTADS=0x08; // Output Drive Strength Selection
PTBD= 0xff; // 1110 1110
PTBDD=0xff; // 0000 0000
//PTBPE=0xff;// Internal Pullup Enable
//PTBSE=0xff; // Output Slew Rate Control Enable
//PTBDS=0x00; // Output Drive Strength Selection
//SPMSC3 = 0x00;
}

void main(void)
{

EnableInterrupts; /* enable interrupts */
/* include your code here */
InitPort();
InitIcs();
// InitAD();
InitSys();
SRTISC=0x57;
count =20;
jishu =10;
display_init();
send_data(0b10100000,3); //送3位“写 ”模式命令代码101
send_data(0,6); //送6位首地址00h
send_data(0xaa,8); //送3位“写 ”模式命令代码101
send_data(0xff,8); //送6位首地址00h
//ds1302_write_time();
for(;;) {
//ds1302_read_time();
//ad_deal();



// __RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}

interrupt void _Vrti_Int()
{

SRTISC_RTIACK = 1;
time1++;
count--;
if(count == 0)
{
count = 20;
disbuf[3] =time1&0x0f;
disbuf[2] =(time1>>4)&0x0f;
disbuf[1] =(time1>>8)&0x0f;
disbuf[0] =(time1>>12)&0x0f;
display(); //刷新1621的缓存
PTBD_PTBD6 = ~PTBD_PTBD6;
}
感谢!先!
你的程序跑过吗,能跑通吗?中断能响应吗?中断函数放入非分页地址了吗?
海纳百川  有容乃大
中断能跑起来,PTBD_PTBD6 也能取反!就是不能点亮液晶。谢谢。
有没有用示波器看过通信波形?
海纳百川  有容乃大
呵呵,老大呀,现在手头没有示波器,您帮我看一下,mc9s08的设置正确吗?是不是有可能我输出时序不对呀? mc9s08qg4我使用内部晶振。

[此贴子已经被作者于2008-1-15 16:51:08编辑过]

返回列表