求一个正确的程序
这是我写的程序
[mw_shl_code=c,true]#include<stc12c5a60s2.h>
#define uchar unsigned char
#define uint unsigned int
uint GBcode;
xdata uchar a_dot[32],a_dot_1[256];
void save();
void led();
//uchar temp;
/*-------------------------------------------
引脚连接宏定义
------------------------------------------------*/
sbit GT_CS = P1^0;
sbit GT_SO = P3^5;
sbit GT_SI = P1^2;
sbit GT_CLK = P1^3;
/*点阵定义*/
sbit LA = P0^0; //138译码输入
sbit LB = P0^1;
sbit LC = P0^2;
sbit LD = P0^3; //138译码输入
sbit R1_595 = P0^4; //红数据输入1
sbit R2_595 = P0^5; //红数据输入2
sbit EN = P2^1; //输出使能
sbit LT = P2^2; //锁存
sbit SK = P2^3; //时钟
void delay(uchar i)
{
uchar x,y;
for(x=i;x>0;x--)
for(y=110;y>0;y--);
}
/*--------------------------------------------------
函数名 :ReadByte
功能 :读取任意地址数据
输入参数:
输出参数:
--------------------------------------------------- */
unsigned char ReadByte(unsigned long Address)
{
unsigned char i = 0,j = 0,temp = 0x0B;
GT_CS = 0;
//发送指令
for(i=0; i<8; i++)
{
GT_CLK = 0;
GT_SI = temp&0x80;
temp <<= 1;
GT_CLK = 1;
}
//发送地址
for(j=1; j<4; j++)
{
temp = ( (unsigned char*)&Address )[j] ;
for(i=0; i<8; i++)
{
GT_CLK = 0;
GT_SI =temp & 0x80;
temp <<= 1;
GT_CLK = 1;
}
}
//发送空字节
for(i=0; i<8; i++)
{
GT_CLK = 0;
GT_SI = 0;
GT_CLK = 1;
}
//接收数据
for(j=0;j<32;j++)
{
for(i=0; i<8; i++)
{
GT_CLK = 0;
temp <<= 1;
if(GT_SO)temp |= 0x01;
else temp &= 0xFE;
GT_CLK = 1;
}
a_dot[j]=temp;
}
GT_CS = 1;
}
/*GB2312 功能: 把Unicode内码转换为GB2312内码
参数: srcCode:输入Unicode内码串。
destCode:转换后得到的GB2312内码串。*/
//
//uint UnicodeToGB2312(uint code1)
//{
//unsigned char i = 0,j = 0,temp = 0x0b;
//unsigned long ptr,result=0;
//uchar GB2312Code[2];
//unsigned long UToGb2312Buff =0x67d70;
//uint h;
////uchar UCSadd1,UCSadd2,UCSadd3;
//if(code1<0xa0) result=1;
//else if(code1<=0xf7) h=code1-160;
//else if(code1<0x2c7) result=1;
//else if(code1<=0x2c9) h=code1-160-463;
//else if(code1<0x2010) result=1;
//else if(code1<=0x2312) h=code1-160-463-7494;
//else if(code1<0x2460) result=1;
//else if(code1<=0x2642) h=code1-160-463-7494-333;
//else if(code1<0x3000) result=1;
//else if(code1<=0x3017) h=code1-160-463-7494-333-2493;
//else if(code1<0x3220) result=1;
//else if(code1<=0x3229) h=code1-160-463-7494-333-2493-520;
//else if(code1<0x4e00) result=1;
//else if(code1<=0x9b54) h=code1-160-463-7494-333-2493-520-7126;
//else if(code1<0x9c7c) result=1;
//else if(code1<=0x9ce2) h=code1-160-463-7494-333-2493-520-7126-295;
//else if(code1<0x9e1f) result=1;
//else if(code1<=0x9fa0) h=code1-160-463-7494-333-2493-520-7126-295-316;
//else if(code1<0xe76c) result=1;
//else if(code1<=0xe774) h=code1-160-463-7494-333-2493-520-7126-295-316-18379;
//else if(code1<0xff00) result=1;
//else if(code1<=0xff5f) h=code1-160-463-7494-333-2493-520-7126-295-316-18379-6027;
//else if(code1<0xffe0) result=1;
//else if(code1<=0xffe5) h=code1-160-463-7494-333-2493-520-7126-295-316-18379-6027-128;
//else result=1;
//if(result==0)
//{
// ptr = UToGb2312Buff + (h<<1); //UCS2转GB2312在芯片的首地址
//}
//else
//{
// ptr=0x0000a1a1;
//}
////UCSadd1=ptr/65536;
////UCSadd2=ptr/256;
////UCSadd3=ptr%256;
//GT_CS = 0;
// //发送指令
// for(i=0; i<8; i++)
// {
// GT_CLK = 0;
// GT_SI = temp&0x80;
// temp <<= 1;
// GT_CLK = 1;
// }
// for(j=1; j<4; j++)
// {
// temp = ( (unsigned char*)&ptr )[j] ;
// for(i=0; i<8; i++)
// {
// GT_CLK = 0;
// GT_SI =temp & 0x80;
// temp <<= 1;
// GT_CLK = 1;
// }
//
// }
// //发送空字节
// for(i=0; i<8; i++)
// {
// GT_CLK = 0;
// GT_SI = 0;
// GT_CLK = 1;
// }
// for(j=0;j<2;j++)
// {
// for(i=0;i<8;i++)
// {
// temp=temp<<1;
// GT_CLK = 0;
// GT_CLK = 1;
// if(GT_SO) temp++;
// }
// GB2312Code[j]=temp;
// }
// GT_CS=1 ;
// GBcode=GB2312Code[0]*256+GB2312Code[1]; //高地位组合
// return (GBcode);//返回GB2312汉字编码
//
//}
void hangout(uchar hang)
{
LA=hang&0x01;
LB=hang&0x02;
LC=hang&0x04;
LD=hang&0x08;
}
void Send_595(uchar dat,uchar dat1)//双参数,时钟、单锁存共用,双数据输出
{
uchar i;
for(i=0; i<8; i++)
{
SK = 0;//拉低同步时钟
dat >>= 1;//数据移位
R1_595=~CY;//数据位输出
dat1>>=1;//数据1移位
R2_595=~CY;//数据1位输出
SK = 1;//恢复同步时钟
}
}
void led(uint GB_code)
{
uchar MSB,LSB,ADH;
unsigned long Address,BaseAdd;
MSB= GB_code/256;
LSB= GB_code%256;
BaseAdd=0;
if(MSB == 0xA9 && LSB >=0xA1)
Address =(282 + (LSB - 0xA1))*32+ BaseAdd;
else if(MSB >=0xA1 && MSB <= 0xA3 && LSB >=0xA1)
Address =( (MSB - 0xA1) * 94 + (LSB - 0xA1))*32+ BaseAdd;
else if(MSB >=0xB0 && MSB <= 0xF7 && LSB >=0xA1)
Address = ((MSB - 0xB0) * 94 + (LSB - 0xA1)+ 846)*32+ BaseAdd;
// ADH=Address/0x10000;
delay(2);
ReadByte(Address);
delay(2);
}
void main()
{
unsigned int j;
// uchar temp,temp1;
P3M1=0X10;
P3M0=0X00;
// UnicodeToGB2312(0x554a);
led(0xB0A2);
delay(2);
while(1)
{
for(j=0;j<16;j++)
{
Send_595(a_dot[2*j],0);Send_595(a_dot[2*j+1],0);
Send_595(0,0);Send_595(0,0);
Send_595(0,0);Send_595(0,0);
Send_595(0,0);Send_595(0,0);
LT=0;
delay(2);
LT=1;//锁存
hangout(j);//行选
EN=0;//开显示0
delay(1);//显示延时。
EN=1;//关显示 1
}
}
}
[/mw_shl_code]
|