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

📄 main.c

📁 条屏控制器的设计的主程序,本例是控制4字,改动几个边界值即可控制任意长个汉字,保证可以实际应用
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************************/
/*                                                                                        */  
/*                      Controller  Program  V1.4(四字)                                   */
/*                                                                                        */
/*	P3.4、P3.3: 11-RAM, 01-FLASH, 10-245_E, 00-REST										  */
/*	RAM:32K  FLASH:512K  CPU_RAM:4K 													  */
/*	ADDR:   RAM-0x0000~0x7fff   FLASH- (0x0000~0xffff)*8: P1.2、P1.1、P1.0	  		 */
/*	P1.3:XLAT  P1.4:BLANK  P3.5:CPLD_SEL P1.7:Data_sel		P1.5、P1.6:	on standby		  */
/*  P3.2:MAX485_con                                                                       */
/*  Baud:4800pbs                                                                          */
/*                                                                                        */
/*                                                                                        */
/******************************************************************************************/
#pragma small 

#include <reg52.h>

#define DISP_SIZE 	128     //the length of disp_ram:16*2*4
#define	HIGH		1
#define	LOW			0

void init_sys();
void init_ram();
void init_serial_port();
void init_disp();
void get_disp_word();
void get_zimo();
void init_cpld();
void left_move();
void right_move();
void up_move();
void down_move();
void disp_static();
void disp_ram();
void init_interrupt();
void timer();
//void example();
void wait();
      
sbit CPLD_SEL = 0xb5;
sbit DATA_SEL =	0x97;
sbit XLAT 	  =	0x93;
sbit BLANK 	  = 0x94;
sbit MAX485   =	0xb2;
sbit SDA	  =	0x95;
sbit SCL	  = 0x96;
sbit SEL1	  = 0xb4;
sbit SEL0  	  = 0xb3;
sbit FLASH2   = 0x92;
sbit FLASH1   = 0x91;
sbit FLASH0   = 0x90;

unsigned char xdata * disp_ram_addr;	//disp_ram addr
unsigned char xdata * temp_ram_addr;	//zimo addr
unsigned char xdata * hzk_addr;			//hzk addr
unsigned char xdata * asczk_addr;		//ascii addr
unsigned char xdata * disp_word_addr;	//disp_word addr
unsigned char xdata * disp_word_length;	//disp_word_length
unsigned char xdata * word_length_addr; //word_length_addr

unsigned char data 	control_word;		//board control word
unsigned int data 	word_length;			//disp_word_length
unsigned long data 	temp_counter;        //shift counter
unsigned char pdata	temp[16];			//one row data
unsigned char data  move_speed;			//disp speed
unsigned char data 	speed_counter;		//speed counter

unsigned char data 	disp_word;		//disp word per scan
unsigned char xdata * write_addr;		//cpld data addr	
unsigned char xdata * read_addr;		//245_e controller data addr
//unsigned int data count;				//interrupt counter
unsigned char data disp_counter;

main()
{
 init_sys();
 init_ram();
 init_serial_port();
 get_disp_word();
 get_zimo();
 init_disp();
 //disp_static();
 init_cpld();
 //init_interrupt();
 while (1) {
 	CPLD_SEL=LOW;
	BLANK=LOW;
	if (speed_counter==move_speed) {
		left_move();
		//right_move();
 		//up_move();
		//down_move();
        speed_counter=0;
    }
    speed_counter++;	
	disp_ram();
	MAX485=~MAX485;
	}
}

void init_sys()
{ 
 
 //following is init of system
 CPLD_SEL = LOW; 			//CPLD is not be selected
 DATA_SEL = HIGH;           //RED DATA is be selected
 XLAT     = LOW;           //Latch 
 BLANK    = LOW;           //OE no valid
 MAX485   = HIGH;           //RS485 is set to transmit
 SDA      = LOW;			//I2C data is 0
 SCL      = LOW;            //I2C scl
 SEL1     = HIGH;
 SEL0     = HIGH;           //RAM_CE is be selected 
 FLASH2	  = LOW;	
 FLASH1   = LOW;
 FLASH0   = LOW;            //FLASH_0 is be selected 
 
 //following is setup of address
 hzk_addr		= 0x100;  	//hzk addr pointer		FLASH2、FLASH1、FLASH0= 0 0 0
 asczk_addr		= 0x100;	//asczk addr pointer	FLASH2、FLASH1、FLASH0= 1 1 0
 disp_word_addr	= 0x100;	//disp_word pointer		FLASH2、FLASH1、FLASH0= 1 1 1

 disp_ram_addr	= 0x100;	//disp_ram_addr_pointer,length=0x400 					RAM
 temp_ram_addr	= 0x600;	//swap_ram_addr_pointer,length=disp_word_length * 32 	RAM
 write_addr		= 0x580;	//write cpld_data address								CPLD
 read_addr		= 0x581;	//read 245_e control_word address						245_E

 word_length_addr =0x80;	//														RAM	
 
 //followinf is init of variable

 word_length	= 0;
 temp_counter	= 0;
 move_speed		= 1;
 speed_counter	= 0;	
 control_word	= 0x00;
 disp_counter	= 0x00;
}

void init_ram()
{
 unsigned char xdata * addr;
 unsigned int counter; 

 addr = 0x00;
 for (counter=0;counter<0x8000;counter++) {
     *(addr+counter)=0x00;
     }
}

void init_serial_port()
{
 //following is init of serial_port

 TMOD = 0x20;		//定时器T1工作在方式2
 TL1  = 0xf3;		//初值为0xf3 			波特率为14400
 TH1  = 0xf3;		//初值为0xf3			波特率为14400
 SCON=0x50;					//serial port control register
 /*  SM0 SM1-> 0 1 :方式1    SM2->0:单机对单机 REN->1:允许接收
 	 TB8->0:不发送数据第9位  RB8->1:不接收数据第9位 TI->0:发送中断标志复位 RI->1:接收中断标志复位*/

 PCON = 0x80;		//传输速率加倍 
 TR1  = HIGH; 		//启动T1						
 ES=LOW;
 EA=LOW;
}

void get_disp_word()
{
 unsigned int data counter=0;
 
 disp_word=0xff;
 SEL1=HIGH;
 SEL0=LOW;
 FLASH2=HIGH;
 FLASH1=HIGH;
 FLASH0=HIGH;
 for (counter=0;counter<0xff;counter++){
 	control_word= *(read_addr);
	wait();
	}
 SEL1=LOW;
 SEL0=HIGH;
 if ((control_word&0x80)==0x80) {
	while (disp_word!=0x00) {
		while (RI == 0);
		RI=0;
	    disp_word=SBUF;
		*(disp_word_addr+word_length)=disp_word;
		word_length++;
		}
	SBUF=0x55;
	while (!TI);
	TI=0;
	word_length--;
	word_length=word_length/2;
    *(word_length_addr)   = word_length%256;
    *(word_length_addr+1) = word_length/256;
   }
  else
	{
	word_length=*(word_length_addr+1)*256+*(word_length_addr);
	}
}

void get_zimo()
{
 unsigned char data mat[16][2];				//one chinese word zimo   
 unsigned char data qu_ma=0x00,wei_ma=0x00,i=0x00,j=0x00;
 unsigned char data flash_bit=0;	//FLASH select
 unsigned long data seek=0x00;
 unsigned int data word_counter=0;
 
 for (j=0;j<16;j++)
 	for (i=0;i<2;i++)
 		mat[j][i]=0x00;
 word_length=4;
 word_counter=word_length; 
 while (word_counter>0) {
 	SEL1=LOW;SEL0=HIGH;						//select flash
 	FLASH2=HIGH;FLASH1=HIGH;FLASH0=HIGH;	//chinese word address
 	qu_ma=*(disp_word_addr)-0xa0;
 	wei_ma=*(disp_word_addr+1)-0xa0;
 	seek=94*(qu_ma-1)+(wei_ma-1)*32;
 
 	flash_bit=(seek+0x100)/0x10000;
 	FLASH2=flash_bit&0x04;
 	FLASH1=flash_bit&0x02;
 	FLASH0=flash_bit&0x01;

 	hzk_addr=seek+0x100-((seek+0x100)/0x10000)*0x10000;
 	for (j=0;j<16;j++)
 		for (i=0;i<2;i++)
 			mat[j][i]=*(hzk_addr+j*2+i);
 
 	SEL1=HIGH;SEL0=HIGH;					//select ram
 	for (j=0;j<16;j++)
 		for (i=0;i<2;i++)
 			//*(temp_ram_addr+j*2+i)=mat[j][i];
			*(temp_ram_addr+j*2+i)=0x55;
  	temp_ram_addr=temp_ram_addr+32;
  	disp_word_addr=disp_word_addr+2;
 	word_counter--;
 	}
 SEL1=HIGH;SEL0=HIGH;
 //example();
 temp_ram_addr=0x600;
 disp_word_addr=0x100;
}

void init_disp()
{
 unsigned char data counter;

 //for (counter=0;counter<DISP_SIZE;counter++) *(disp_ram_addr+counter)=counter;
 for (counter=0;counter<DISP_SIZE;counter++) *(disp_ram_addr+counter)=0x00;
 for (counter=0;counter<16;counter++) temp[counter]=0x00;
 //for (counter=0;counter<16;counter++) temp[counter]=*(temp_ram_addr+counter*2);
 disp_word=0x00;
}

void init_interrupt()
{
 /* T0工作在方式2,fosc=36MHz, T=10ms,则TC=65536-10000/(1/3)=35536 (0x8ad0) */
 /* fosc=12MHz,则TC=55536(0xd8f0)*/
 TMOD=TMOD|0x01;//T0工作在方式1
 TH0=0xc1;    	//定时器T0初值
 TL0=0x80;
 EA=1;			//开中断	
 ET0=1;			//允许T0中断		
 TR0=1;			//启动T0
}

void timer() interrupt 1 using 2    //中断源为1(T0),使用寄存器组2
{
	TH0=0xc1;    //重装定时器T0初值
 	TL0=0x80;
	/*
	if (speed_counter==move_speed) {
		left_move();
		//right_move();
 		//up_move();
		//down_move();
        speed_counter=0;
    }
    speed_counter++;*/	
	//left_move();
	//speed_counter++;
	disp_ram();
	MAX485=~MAX485;
}

void init_cpld()
{
 SEL1=HIGH;
 SEL0=HIGH;
 SDA = LOW;
 CPLD_SEL=HIGH;
 wait();
 SDA = HIGH;
}

void left_move()
{
 unsigned char data i,j;
 

 if (temp_counter>=(word_length*16+64))
    temp_counter=0;

 if ((temp_counter%8)==0) {
 	if ((temp_counter%16)==0) 
 		for (j=0;j<16;j++) temp[j]=*(temp_ram_addr+j*2+temp_counter*2);
	else
		for (j=0;j<16;j++) temp[j]=*(temp_ram_addr+j*2+temp_counter*2-15);
	}
 temp_counter++; 
 if (temp_counter>word_length*16)
 	for (j=0;j<16;j++) temp[j]=0x00;
 for (j=0;j<16;j++)
 	for (i=0;i<7;i++) 
		*(disp_ram_addr+j*8+i)=((*(disp_ram_addr+j*8+i)<<1)&0xfe)|((*(disp_ram_addr+j*8+i+1)>>7)&0x01);
 for (j=0;j<16;j++)
 	*(disp_ram_addr+7+j*8)=((*(disp_ram_addr+7+j*8)<<1)&0xfe)|((temp[j]>>7)&0x01);

 for (j=0;j<16;j++) temp[j]=temp[j]<<1;
}

void right_move()
{/*
 unsigned char data i,j;
 

 if (temp_counter>=(word_length*16+64)) 
    temp_counter=0;

 if ((temp_counter%8)==0) {
 	if ((temp_counter%16)==0) 
 		for (j=0;j<16;j++) temp[j]=*(temp_ram_addr+j*2+1+temp_counter*2);
	else
		for (j=0;j<16;j++) temp[j]=*(temp_ram_addr+j*2+temp_counter*2-16);
	}

 temp_counter++; 
 for (j=0;j<16;j++)
 	for (i=7;i>0;i--) 
		*(disp_ram_addr+j*8+i)=((*(disp_ram_addr+j*8+i)>>1)&0x7f)|((*(disp_ram_addr+j*8+i-1)<<7)&0x80);
 for (j=0;j<16;j++)
 	*(disp_ram_addr+j*8)=((*(disp_ram_addr+j*8)>>1)&0x7f)|((temp[j]<<7)&0x80);

 for (j=0;j<16;j++) temp[j]=temp[j]>>1;*/
}

⌨️ 快捷键说明

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