//------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
//1、本程序适用于:STC8F系列芯片制作的旋转LED显示屏POV
//2、为方便阅读,使用传统编程思路编写,并未使用框架式编程技巧,
//3、本程序使用24M晶振,STC15 STC8 均可使用
//4、祁绪电子《人人学会单片机》
//------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- //#include "STC15.H"
- #include "STC8.H"
- #include <intrins.h>
- #define u8 unsigned char
- #define u16 unsigned int
- #define u32 unsigned long
- #define zishu 21
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- //------汉字字模保存数组code
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- u8 code hanzi[zishu][32]=
- {
- {0x10,0x40,0x10,0x80,0x91,0x00,0x73,0xFF,0x15,0x00,0x18,0x80,0x00,0x40,0x00,0x00,0x7F,0xFF,0x40,0x20,0x40,0x10,0x44,0x08,0x5B,0x10,0x60,0xE0,0x00,0x00,0x00,0x00},/*"祁",0*/
- /* (16 X 16 , 宋体 ) */
- {0x04,0x44,0x0C,0xE6,0x35,0x44,0xC6,0x48,0x08,0x48,0x04,0x20,0x24,0x40,0x24,0xFF,0x25,0x92,0xFE,0x92,0x24,0x92,0x2C,0x92,0x14,0xFF,0x64,0x00,0x04,0x00,0x00,0x00},/*"绪",1*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x00,0x00,0x00,0x1F,0xF8,0x11,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0xFF,0xFE,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x1F,0xF9,0x00,0x01,0x00,0x0F,0x00,0x00},/*"电",2*/
- /* (16 X 16 , 宋体 ) */
- {0x01,0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x02,0x41,0x01,0x47,0xFE,0x45,0x00,0x49,0x00,0x51,0x00,0x61,0x00,0x41,0x00,0x01,0x00,0x01,0x00,0x00,0x00},/*"子",3*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x0C,0x00,0x00},/*"L",5*/
- /* (8 X 16 , 宋体 ) */
- {0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x17,0xC4,0x10,0x04,0x08,0x18,0x00,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"D",7*/
- /* (8 X 16 , 宋体 ) */
- {0x08,0x01,0x08,0x06,0x8F,0xF8,0x69,0x02,0x09,0x01,0x09,0xFE,0x08,0x01,0x14,0x06,0xE4,0xF8,0x24,0x04,0x27,0xFE,0x24,0x22,0x24,0x22,0x27,0x22,0x20,0x02,0x00,0x00},/*"旋",8*/
- /* (16 X 16 , 宋体 ) */
- {0x13,0x10,0x1D,0x18,0xF1,0x10,0x17,0xFF,0x11,0x20,0x11,0x20,0x02,0x00,0x12,0x40,0x12,0xD0,0x17,0x48,0xFA,0x44,0x12,0x4B,0x12,0x50,0x12,0x60,0x02,0x00,0x00,0x00},/*"转",9*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x01,0x00,0x02,0x03,0xEC,0x02,0x20,0x02,0x20,0x02,0x28,0xFE,0x26,0x12,0x20,0x12,0x28,0x12,0x26,0x12,0x20,0x13,0xE0,0x10,0x08,0x10,0x07,0x00,0x00,0x00,0x00},/*"点",10*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x00,0x7F,0xFF,0x40,0x10,0x44,0x08,0x5B,0x10,0x60,0xE0,0x10,0x10,0x13,0x10,0x1D,0x10,0xF1,0x10,0x17,0xFF,0x11,0x10,0x11,0x10,0x11,0x10,0x10,0x10,0x00,0x00},/*"阵",11*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x02,0x00,0x42,0x00,0x22,0x7F,0x1A,0x49,0x02,0x49,0xFE,0x49,0x02,0x49,0x02,0x49,0x02,0x49,0xFE,0x49,0x02,0x7F,0x0A,0x00,0x12,0x00,0x62,0x00,0x02,0x00,0x00},/*"显",12*/
- /* (16 X 16 , 宋体 ) */
- {0x02,0x04,0x02,0x08,0x42,0x10,0x42,0x60,0x42,0x00,0x42,0x02,0x42,0x01,0x43,0xFE,0x42,0x00,0x42,0x00,0x42,0x00,0x42,0x40,0x42,0x20,0x02,0x10,0x02,0x0C,0x00,0x00},/*"示",13*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x02,0x00,0x0C,0x7F,0xF0,0x48,0x20,0x49,0x21,0x4D,0x26,0x4B,0xF8,0x49,0x20,0x49,0x20,0x49,0x20,0x4B,0xFF,0x4D,0x20,0x79,0x20,0x00,0x20,0x00,0x00,0x00,0x00},/*"屏",14*/
- /* (16 X 16 , 宋体 ) */
- {0x04,0x08,0x04,0x0C,0xFF,0xF8,0x04,0x10,0x04,0x10,0x1F,0x80,0x90,0xBF,0x54,0xAA,0x12,0xAA,0x1F,0xAA,0x12,0xAA,0x54,0xAA,0x90,0xBF,0x1F,0x80,0x00,0x00,0x00,0x00},/*"增",16*/
- /* (16 X 16 , 宋体 ) */
- {0x40,0x00,0x47,0xC2,0x44,0x41,0x44,0x42,0x7C,0x7C,0x00,0x02,0x01,0xE2,0x79,0x22,0x49,0x22,0x49,0x22,0x4F,0xFE,0x49,0x22,0x49,0x22,0x79,0x2A,0x01,0xE7,0x00,0x00},/*"强",17*/
- /* (16 X 16 , 宋体 ) */
- {0x04,0x22,0x44,0x42,0x45,0x92,0x7E,0x12,0x44,0x12,0x44,0x12,0x7F,0x92,0x44,0x7E,0x44,0x12,0x00,0x12,0x3E,0x12,0x00,0x92,0x00,0x52,0xFF,0x82,0x00,0x02,0x00,0x00},/*"型",18*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x00,0x0E,0x1C,0x11,0x04,0x10,0x84,0x10,0x84,0x10,0x44,0x1C,0x38,0x00,0x00,0x18,0x00,0x10,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x00,0x18,0x00,0x00,0x00},/*"T",20*/
- /* (8 X 16 , 宋体 ) */
- {0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x08,0x1C,0x10,0x00,0x00,0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00},/*"8",22*/
- /* (8 X 16 , 宋体 ) */
- {0x00,0x08,0x00,0x08,0x1F,0xC8,0x92,0x48,0x52,0x48,0x32,0x48,0x12,0x48,0x1F,0xFF,0x12,0x48,0x32,0x48,0x52,0x48,0x92,0x48,0x1F,0xC8,0x00,0x08,0x00,0x08,0x00,0x00},/*"单",23*/
- /* (16 X 16 , 宋体 ) */
- {0x00,0x00,0x00,0x01,0x00,0x06,0x7F,0xF8,0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40,0xFC,0x40,0x04,0x7F,0x04,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00,0x00},/*"片",24*/
- /* (16 X 16 , 宋体 ) */
- {0x08,0x20,0x08,0xC0,0x0B,0x00,0xFF,0xFF,0x09,0x00,0x08,0xC1,0x00,0x06,0x7F,0xF8,0x40,0x00,0x40,0x00,0x40,0x00,0x7F,0xFC,0x00,0x02,0x00,0x02,0x00,0x1E,0x00,0x00},/*"机",25*/
- /* (16 X 16 , 宋体 ) */
- };
- u8 xdata LED2X128[262]; //开辟缓存空间,被定时器随时调用。每列两个字节,多加2个用于移位操作。
- sbit HC595_DS=P3^6; //74HC595的数据
- sbit HC595_SH=P3^5; //74HC595的时钟
- sbit HC595_ST=P3^4; //74HC595的锁存
- u16 xdata Timer1_count;
- u8 xdata LED2X128_count=0;
- u8 xdata Timer1_TL1=0xc2;
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- //------LED间距是2.346mm,一圈周长是329.8mm,可以显示16*8=128列+2列黑
- //------转一圈约40ms,一列时间就是40ms/(128+2)=307.7us,定时器再分10份就是31us
- //------定时器1配置:8位,定时时间31us
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- void Timer1_Init()
- {
- AUXR &= 0xBF; //定时器时钟12T模式
- TMOD &= 0x0F; //设置定时器模式
- TMOD |= 0x20; //设置定时器模式
- TL1 = Timer1_TL1; //定时器赋初始值256-(24000000÷12T÷130列÷25帧÷10份)
- TH1 = Timer1_TL1; //定时器赋初始值256-(24000000÷12T÷130列÷25帧÷10份)
- TF1 = 0; //清除TF1标志
- TR1 = 1; //定时器1开始计时
- ET1=1;
- }
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- //------定时器1中断处理,
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- void Timer1_Routnie (void) interrupt 3
- {
- u16 k; //总共显示130列
- Timer1_count++;
- if(Timer1_count%10==1)
- {
- LED2X128_count=LED2X128_count%260;//8个字*16列+2黑,每列2字节=(8*16+2)*2=260
- k=256-LED2X128_count;
-
- if(k<128)
- {
- P4=~LED2X128[k];
- P2=~LED2X128[k+1];
- P1=~LED2X128[k+128];
- P0=~LED2X128[k+129];
- }
- else //两边的正好错开180度,所以只需要显示半圈
- {
- P4=255;
- P2=255;
- P1=255;
- P0=255;
- }
- LED2X128_count+=2;
- }
- }
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- //------下降沿中断INT3 接收红外PT928的下降沿
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- void INT3_Routnie() interrupt 11
- {
- if(Timer1_count>1305) //如果转一圈时间长了,那么定时器初值减少1 定时时间延长
- {
- Timer1_TL1--;
- TL1 = Timer1_TL1;
- TH1 = Timer1_TL1;
- }
- else if(Timer1_count<1285) //如果转速变快,那么定时器初值增加1 定时时间减少
- {
- Timer1_TL1++;
- TL1 = Timer1_TL1;
- TH1 = Timer1_TL1;
- }
- LED2X128_count=0; //定位点从新开始显示
- Timer1_count=0; //定位点重新计时
- }
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- //------主函数
- //------------------------------------------------------------------------------------------------祁绪电子《人人学会单片机》 ------
- void main() //主函数
- {
- u16 i,count;
- u8 num=0,ww=0;
- INTCLKO |= 0x20; //外部中断3下降沿中断允许
- Timer1_Init();
- EA=1;
- for(i=0;i<260;i++)
- {
- LED2X128[i]=hanzi[i/32+1][i%32];
- }
- while(1)
- {
- count=65000;
- while(count--);
-
- LED2X128[260]=hanzi[ww][num];
- num++;
- LED2X128[261]=hanzi[ww][num];
- num++;
- if(num>=32)
- {
- num=0;
- ww++;
- if(ww>=zishu)
- {
- ww=0;
- }
- }
- for(i=0;i<260;i++)
- {
- LED2X128[i]=LED2X128[i+2];
- }//*/
- }
- }
复制代码 |