⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 200351913433525162.c

📁 c语言写的字符叠加程序
💻 C
字号:
#include <reg51.h>
#include <intrins.h>

typedef unsigned char uchar;

//uPD6453脚的运用
sbit DATA6453=P3^2;
sbit CLK6453=P3^4;
sbit CS6453=P3^3;
sbit BUSY6453=P3^5;




/*uPD6453 COMMAND LIST*/	
//1-BYTE COMMAND
#define DISLOW4 0X0C 
       /*D3=D0 0/1--dispLAY 0FF/ON
         D2=LOSC 0/1--Oscillation OFF/ON
         D1,D0=BL1,BL0 00(Blinking OFF) 
                       01(Blinking frequency:about 2 Hz Blinking ratio:1:1)
					   10(Blinking frequency:about 1 Hz Blinking ratio:1:1)
					   11(Blinking frequency:about 0.5 Hz Blinking ratio:1:1)*/
#define BACKLOW3 0X00
        /*D2,D1=BS1,BS0 00(NO BACKGROUND)
		                01(VidEO-REVERSED BACKGROUND)
						10(DO NOT USE THIS COMBINATION)
						11(SOLid BACKGROND)
		  D0=BF  0/1--Fringing OFF/ON				*/
#define BACKLOW4 0X00
        /*D3,D2,D1=Rb,Gb,Bb 000(black) 001(blue) 010(green)	011(cyan)
							100(red) 101(magenta) 110(yellow) 111(white)
		  D0=BFC 0/1--Fringe color black/white */
#define PROGLOW2 0X00
        /*D1,D0=VC,HC 00(NORMAL TV MODE)
	                  01(SELECTABLE NORMAL TV MODE)
		        	  10(DEDICATED/SELECTABLE PROGRESSIVE TV MODE)
					  11(PROGRESSIVE TV MODE)*/

/*显示控制 确定是否允许显示字符、字符的闪烁频率,及控制LC振荡的停振和起振*/	   
#define dispLAY 0x00|DISLOW4 
/*背景控制 确定背景的类型(无背景、字符边缘背景、字符块背景、全屏幕背景*/
#define BACKGROUND 0x40|BACKLOW3
/*背景颜色控制 确定背景的颜色*/
#define BACKGROUNDCOLOR 0x10|BACKLOW4
/**/
#define PROGRESSIVESCAN 0x30|PROGLOW2
/*视频RAM复位 此时晶振起振,视频RAM写模式,字符的颜色、大小等为默认设置*/
#define VidEO_RAM_ALL_RESET 0x34

//2-byte command
#define POSILOW2 0X00
#define POSI8 0X00
        /*D9,D8,D7,D6,D5=V4,V3,V2,V1,V0--Vertical address specification bits
	                     00000(note:9(18)x0H) 9-Normal TV ()--progressive TV
					     00001(note:9(18)x1H)
						 .....
						 11111(note:9(18)x31H) 
		 D4,D3,D2,D1,D0=H4,H3,H2,H1,H0--Horizontal address specification bits
		                 00000(note:12(24)/fosc(MHZ)x1[us])
						 00001(note:12(24)/fosc(MHZ)x2[us])
						 .....
						 11111(note:12(24)/fosc(MHZ)x32[us])*/
#define ADDRLOW1 0X00
#define ADDR8 0X00
        /*D8,D7,D6,D5=AR3,AR2,AR1,AR0 LINE addressing bits
		              0000(set the 1st line)
					  0001(set the 2nd line)
					  ....
					  1011(set the 12th line)
		 D4,D3,D2,D1,D0=AC4,AC3,AC2,AC1,AC0 column addressing bits
	                    00000(set the 1st line)
						00001(set the 2nd line)
						.....
						10111(set the 24th line) */  
#define RAMADDRLOW1 0X00
#define RAMADDR8 0X00
        /*D8,D7,D6,D5=RW3,RW2,RW1,RW0 --word address specification bits 
		                              0000(Set 1st word)
	                                  0001(set 2nd word)
									  ....
									  1111(set 16th word)
		 D4,D3,D2,D1,D0=RL4,RL3,RL2,RL1,RL0--line address specification bits
		                              00000(set 1st line)
									  00001(set 2nd line)
									  .....
									  10001(set 18th line) */
#define SSMPLOW3 0X00
#define SSMP8 OX00
        /*D10=MP Mask pulse control bit 0/1--no mask pulse/mask pulse output
	      D9,D8=S1,S0 Character size contrtol bit
		        00--normal character size
				01--twice the normal size
				10--three times the normal size
				11--four times the normal size
		 D7,D6,D5,D4=0,0,SM1,SM0  Smooth control bit d7,d6--always set "0"
		                  0,x(no smooth function)
						  1,0(class 1 smooth)
						  1,1(class 2 smooth)
		D3,D2,D1,D0=AR3,AR2,AR1,AR0--Line address control bits
                    0000(set 1st line)
					0001(set 2nd line)
					....
					1011(set 12th line)*/	   
#define RAMDATALOW4 0X00
#define RAMDATA8 0X00
        /*D11,D10....D0=CR11,CR10..CR0
	         CR XX --Character RAM write data control bits
			    0--without dots
				1--with dots*/
#define TEST8 0X00
/*显示块位置控制 用来确定12行24列的字符显示块离屏幕最上端、最左端的距离*/
#define dispLAY_POSITION1 0X80|POSILOW2
#define dispLAY_POSITION2 POSI8
/*显示字符行、列地址控制 确定字符在12行24列的显示块中的行列位置*/
#define CHARACTER_WRITE_ADDRESS1 0X84|ADDRLOW1
#define CHARACTER_WRITE_ADDRESS2 ADDR8
/*UPD6453内部提供16个字符的RAM空间,每个字符为12*18点阵,该命令用来确定将
  点阵数据写入RAM空间中第几个字的第几行(一共18行),写完一行,行地址自动
  加1,写完一个字,字地址自动加1。*/
#define CHARACTER_RAM_WRITE_ADDRESS1 0X86|RAMADDRLOW1
#define CHARACTER_RAM_WRITE_ADDRESS2 RAMADDR8
/*字符大小、平滑控制  确定每一行字符的显示大小,以及用多倍显示时是否采用
  字符的平滑措施*/
#define CHARACTER_SSMP1 0X88|SSMPLOW3 
#define CHARACTER_SSMP2 SSMP8
/*字符RAM写数据控制  确定需要写入RAM空间的一行12个点的点阵数据*/
#define CHARACTER_RAM_WRITE_DATA1 0X90|RAMDATALOW4
#define CHARACTER_RAM_WRITE_DATA2 RAMDATA8
#define TEST_MODE1 0XA0
#define TEST_MODE2 TEST8
//2nd byte continuous command
/*显示字符控制 确定芯片UPD6453的256个字符(包括固化的240个字符以及16个自定义
  字符)中哪个字符送出显示,以及该字符的显示颜色是否闪烁*/
#define display_character1 0XC0|CHARLOW4
#define display_character2 CHAR8
#define CHARLOW4 0X09
#define CHAR8 0X05
     
void init_serial(void)
{
	SP = 0x40;
    SCON  = 0x51;       
	TMOD |= 0x21;       
	PCON  = 0x00;//PCON |= 0x80;       //SMOD=1;
	TH1   = 0xFD;       //Baud:9600  fosc=11.059200MHz
    TL1   = 0xFD;
	IE   |= 0x90;       //Enable Serial Interrupt 中断允许寄存器开
    TR1   = 1;          // timer 1 run
    CLK6453=1;
    DATA6453=1;
    CS6453=1;
    BUSY6453=1;  
}

static void RLDATA(uchar ch)
{
     uchar i=8;
	  while (BUSY6453);
	  do
     {
          CLK6453=0;
          DATA6453=(bit)(ch&0x80);        //强制取为位变量,输出
          ch=ch<<1;                 //右移一位
          CLK6453=1;
     }  
     while(--i);
//     DATA6453=1;
}

main()
{
//char x;
uchar w,i;
init_serial();
w=VidEO_RAM_ALL_RESET;//复位
CS6453=0;
RLDATA(w);
CS6453=1;
_nop_();
w=dispLAY;//显示控制
CS6453=0;
RLDATA(w);
CS6453=1;
_nop_();

w=0x40;
CS6453=0;
RLDATA(w);
CS6453=1;
_nop_();

w=0x10;
CS6453=0;
RLDATA(w);
CS6453=1;
_nop_();

w=0x30;   /* Progressive scan control command                */
CS6453=0;
RLDATA(w);
CS6453=1;
_nop_();                                           
for (i = 0; i < 12; i++) {                                           
CS6453=0;
w=0x88;
RLDATA(w);
RLDATA(0x30+i);
CS6453=1;
}
_nop_(); 
   
CS6453=0;
w=0x80;
RLDATA(w);
w=0xa5;
RLDATA(w);
CS6453=1;
_nop_();
w=display_character1;//显示字符控制
CS6453=0;
RLDATA(w);
w=display_character2;
RLDATA(w);
CS6453=1;
while (1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -