大家好。我有一块64x128LED全彩点阵屏,HUB75E接口,可以显示4排每排8个16x16的汉字。
用STC8H3K64S单片机核心板,在网上搜了一个32x64的LED屏代码。
添加一下行扫描(原本是16扫,改成32扫),屏点亮,显示两幅相同画面,右幅比左幅整个要上移一行,如图1。
继续修改其它参数,第1和3排可以完整显示,第2和4排只显示上8行,下8行被条纹覆盖。如图2。
如果让主程序只运行Timer1_Init()和DZ64X32_Write_Buffer(),点阵屏第2和第4组下8行出现条纹,如图3
源代码附上,修改过的地方已经标注出来了。
向大家请教,这个代码怎样修改才能完美点亮这块64x128的屏。先谢谢了。
单片机源程序如下:
- #include <stc8h.h>
- #include <intrins.h>
- #define FOSC 22118400L
- #define BAUD 38400
- #define uint unsigned int
- #define uchar unsigned char
- //HUB75引脚
- sbit R0 = P0^0; sbit G0 = P1^0;
- sbit B0 = P0^1; //接地
- sbit R1 = P0^2; sbit G1 = P1^1;
- sbit B1 = P0^3; sbit HC_138E = P1^2;
- sbit HC_138A = P0^4; sbit HC_138B = P1^6;
- sbit HC_138C = P0^5; sbit HC_138D = P1^7;
- sbit RGB_CLK = P0^6; sbit LE = P2^0;//LAT
- sbit OE = P0^7; //接地
- void DZ64X32_Write_Buffer();
- void SM16126_Send_Data();
- void HC138_Sel(uchar hang);
- void LED_Tu(uchar x,uchar y,uchar num,uchar Background);
- uchar code Tu_16X16[][32]; //***********************************
- #define T10MS12T (65536-FOSC/12/3000)//967 //原值1000,画面闪动,改成3000就稳定了
- #define T1MS12T (65536-FOSC/12/1000) //************************************
- void Timer1_Init()//主刷新定时器
- {
- TL0 = T10MS12T;
- TH0 = T10MS12T>>8;
- TR0 = 1;
- ET0 = 1;
- }
- void TM1_Rountine(void) interrupt 1
- {
- SM16126_Send_Data();
- }
- void HC138_Sel(uchar hang)//hang 选择
- {
- HC_138A=hang&0x01;
- HC_138B=hang&0x02;
- HC_138C=hang&0x04;
- HC_138D=hang&0x08;//***********************************
- HC_138E=hang&0x10;//改成32扫
- } //******************************************
- //数据存储方式,因为汉字需要左右滚动,所以上下两16行存储在同一Byte
- #define C_0 0
- #define C_R 0x09
- #define C_G 0x0A
- #define C_B 0x0C
- #define C_RG 0x0B
- #define C_RB 0x0D
- #define C_GB 0x0E
- #define C_RGB 0x0F
- uchar bdata dat;
- /*
- 0 1 2 3 4 5 6 7
- R G B L R G B H
- L存储是否点亮,R,G,B存储值
- 一个点需要4bit,一共是32*64*4=32*32Byte
- */
- sbit dat_RL=dat^0;
- sbit dat_GL=dat^1;
- sbit dat_BL=dat^2;
- sbit dat_LL=dat^3;
- sbit dat_RH=dat^4;
- sbit dat_GH=dat^5;
- sbit dat_BH=dat^6;
- sbit dat_LH=dat^7;
- uchar Point_color;//取值范围0,9-15,同时//********************************************************
- uchar xdata RGB_DZ64X32_Buffer[32][128];//原值为32和64;点亮64x128点阵屏
- //显示分左右两相同内容,右边内容上移壹行。如图1.
- void DZ64X32_Write_Buffer() //改成32和128时,第2和第4排的上部8行显示正常,
- { //下8行位置被条纹覆盖,如图2.
- uchar i,j; //*******************************************************
- for(i=0;i<32;i++)
- {
- for(j=0;j<128;j++)
- {
- RGB_DZ64X32_Buffer[i][j]=0x00;
- }
- }
- }
- void SM16126_Send_Data()
- {
- uchar i;
- static uchar hang;
-
- RGB_CLK=0;//低电平
- LE=1;//允许数据,
- OE=1;//失效,不亮
- //****************************************
- for(i=0;i<128;i++) //64列是原值,改成128列
- { //****************************************
- dat=RGB_DZ64X32_Buffer[hang][i];//取出数据
- RGB_CLK=0;
- //---上半屏
- if(dat_LL)//有数据
- {
- R0=dat_RL;
- G0=dat_GL;
- B0=dat_BL;
- }
-
- else//没有数据
- {
- R0=0;
- G0=0;
- B0=0;
- }
- //---下半屏
- if(dat_LH)//有数据
- {
- R1=dat_RH;
- G1=dat_GH;
- B1=dat_BH;
- }
-
- else//没有数据
- {
- R1=0;
- G1=0;
- B1=0;
- }
- RGB_CLK=1;//上升沿数据吸收
- }
-
- LE=0;//禁止输入
- HC138_Sel(hang);//行选
- hang++; //*************************************
- hang&=0x1f; //原值是0x0f,0~15 16行;改成0x1f,0~31 32行
- OE=0;//点亮 //***************************************
- }
- void DZRGB_DrawPoint(uchar x,uchar y)
- {
- uchar da,db;
- if(Point_color)//有亮度
- {
- if(y>=32)//在高位 //************************************
- { //原值16,改成32
- y-=32; //**************************************
- da=Point_color<<=4;//移动到高位
-
- db=RGB_DZ64X32_Buffer[y][x];//取出数据
- db&=0X0F;//清除高位00001111
-
- RGB_DZ64X32_Buffer[y][x]=db+da;
- }
- else//在低位
- {
- db=RGB_DZ64X32_Buffer[y][x];//取出数据
- db&=0XF0;//清除低位 11110000
-
- RGB_DZ64X32_Buffer[y][x]=db+Point_color;
- }
- }
- else//没有亮度
- {
- if(y>=32)//在高位
- {
- y-=32;
- RGB_DZ64X32_Buffer[y][x]&=0x7F;//01111111
- }
- else
- {
- RGB_DZ64X32_Buffer[y][x]&=0xE7;//11100111
- }
- }
- }
- uchar code er[8]={1,2,4,8,16,32,64,128};
- void LED_Tu(uchar x,uchar y,uchar num,uchar Background)
- {
- uchar i,j;
- uchar Point_color_Save;
- Point_color_Save=Point_color;//保存颜色
- for(j=0;j<16;j++)//16列
- {
- for(i=0;i<8;i++)//前8行
- {
- if(Tu_16X16[num][j]&er[i])
- {
- Point_color=Point_color_Save;
- }
- else
- {
- Point_color=Background;
- }
- DZRGB_DrawPoint(x+j,y+i);
- }
- }
- for(j=0;j<16;j++)//16列
- {
- for(i=0;i<8;i++)//后8行
- {
- if(Tu_16X16[num][j+16]&er[i])
- {
- Point_color=Point_color_Save;
- }
- else
- {
- Point_color=Background;
- }
- DZRGB_DrawPoint(x+j,y+8+i);
- }
- }
- Point_color=Point_color_Save;
- }
- void main()
- {
- P2M0=0x00;P2M1=0X00;
- P1M0=0X00;P1M1=0X00;
- P0M0=0X00;P0M1=0X00;
- //*******************************************
- Timer1_Init(); //主程序只运行Timer1_Init();DZ64X32_Write_Buffer(); .
- DZ64X32_Write_Buffer(); //点阵屏第2和第4组下8行出现条纹,如图3
- //*******************************************
- // Point_color=C_R;
- // LED_Tu(0,0,1,C_0);LED_Tu(48,0,5,C_0);
- // LED_Tu(0,16,2,C_0);LED_Tu(48,16,10,C_0);
- // Point_color=C_G;
- // LED_Tu(0,32,3,C_0);LED_Tu(48,32,7,C_0);
- // LED_Tu(0,48,4,C_0);LED_Tu(48,48,8,C_0);
-
- EA=1; //打开总中断
- while(1)
- {
-
- }
- }
- uchar code Tu_16X16[][32]={ //阴码 顺向 行列扫描
- 0x10,0x0C,0x05,0x55,0x55,0x55,0x85,0x7F,0x85,0x55,0x55,0x55,0x05,0x14,0x0C,0x00,
- 0x04,0x04,0x02,0x0A,0x09,0x29,0x2A,0x4C,0x48,0xA9,0x19,0x02,0x02,0x04,0x04,0x00, //"零",0
- 0x00,0xC4,0x44,0x54,0x54,0x54,0x54,0x5F,0x54,0x54,0x54,0x54,0x44,0x44,0xC0,0x00,
- 0x81,0x80,0x80,0x9D,0xB5,0xD5,0x95,0x95,0x95,0xD5,0xB5,0x9D,0x80,0x81,0x80,0x00, //"壹",1
- 0x04,0x44,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0x04,0xFF,0x04,0x05,0x06,0x04,0x00,
- 0x00,0x80,0x9F,0x41,0x21,0x1D,0x21,0x41,0x9F,0x00,0x01,0x0E,0x30,0x40,0xF0,0x00, //"贰",2
- 0x00,0x20,0x20,0xA8,0x6C,0x2A,0x39,0x28,0x28,0x2A,0x6C,0xA8,0x20,0x20,0x00,0x00,
- 0x02,0x02,0x41,0x40,0x48,0x49,0x49,0x49,0x49,0x49,0x48,0x40,0x41,0x02,0x02,0x00, //"叁",3
- 0x00,0x00,0xFE,0x92,0x92,0x92,0x02,0x10,0x54,0x54,0xFF,0x54,0x54,0x7C,0x10,0x00,
- 0x44,0xE4,0x5F,0x44,0x44,0x54,0xE4,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x10,0x00, //"肆",4
- 0x00,0x80,0x60,0xF8,0x07,0x00,0x42,0x42,0xC2,0x7E,0x42,0x42,0xC2,0x02,0x00,0x00,
- 0x01,0x00,0x00,0xFF,0x00,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x7F,0x40,0x40,0x00, //"伍",5
- 0x00,0xFE,0x02,0x22,0xDA,0x06,0x80,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x80,0x00,
- 0x00,0xFF,0x08,0x10,0x08,0x07,0x00,0x7C,0x40,0x40,0x7F,0x40,0x40,0xFC,0x00,0x00, //"陆",6
- 0x00,0x88,0x91,0x42,0x20,0x08,0x08,0x08,0x7F,0x88,0x88,0x84,0x84,0xE4,0x00,0x00,
- 0x44,0x44,0x25,0x24,0x14,0x0C,0x04,0xFF,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x00, //"柒",7
- 0x10,0x10,0xFF,0x10,0x90,0x3E,0xE2,0x22,0x22,0x3E,0x00,0xF8,0x00,0xFF,0x00,0x00,
- 0x42,0x82,0x7F,0x81,0x40,0x31,0x0F,0x41,0x81,0x7F,0x00,0x4F,0x80,0x7F,0x00,0x00, //"捌",8
- 0x04,0x44,0x44,0xFC,0x44,0x44,0x80,0x70,0x0F,0x08,0x08,0xC8,0x38,0x00,0x00,0x00,
- 0x10,0x30,0x10,0x0F,0x08,0x88,0x40,0x20,0x10,0x0C,0x03,0x0C,0x30,0x40,0x80,0x00, //"玖",9
- 0x10,0x10,0x10,0xFF,0x10,0x90,0x20,0x50,0x48,0x44,0x43,0x44,0x48,0x50,0x20,0x00,
- 0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00, //"拾",10
-
- };
复制代码
|