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

📄 dispfinal.c

📁 视频字符叠加系统、采用89系列单片机开发
💻 C
📖 第 1 页 / 共 3 页
字号:
  /*****************************************************************
* one track charactor genrater
******************************************************************
*eeprom define
*16 byte display character code
*60 byte display character information
*others are download character array information
*character code 
*		figure and english character
*		available chinese code 
*		custom code
*serial receive command include
*		dot array download command/code
*		time adjust
*		title setup
******************************************************************/
// the file is suited to at89c51 chip millcrocomputer 22.1184mhz
// BAUD=9600
//define contrain head file
#pragma cd db oe
#include <reg52.h>
//#include <reg516.h>
#include <stdio.h>
#include <string.h>
#include <intrins.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <absacc.h>
//--------------------------------------------------
//define osd6453 command
#define LOCAL_PORT 0x00
#define REC_LENGTH 0x1d
#define clear_vram 0x34
#define normal_tv 0x30
#define selectable_tv 0x31
#define disp_control 0x0e
#define disp_close 0x00
#define background_fring 0x43				//fring on/off control
#define no_background 0x41
#define back_color_fring 0x10				//fring color black background color control 
#define cram_addr 0x86						//write charater dot information addr
#define cram_data 0x90						//write charater dot information
#define charsize 0x8c						//
#define char_twice_size 0x8d
#define disp_position_high 0x80
#define disp_position_low 0xc4         //change from c5 to c4  3.26
#define char_position 0x84					//the display charater position
#define char_attribute 0xc8
#define char_blink 0xc9
#define smooth 0x30

//----------------------------------------------------------

//-----------------------------------------------------------
//define bit 
static struct date_clock
		{
		unsigned char date_lines;
		unsigned char date_words;
		unsigned int  years;
		unsigned char months;
		unsigned char dates;
		unsigned char time_lines;
		unsigned char time_words;
		unsigned char hours;
		unsigned char minutes;
		unsigned char seconds;
		unsigned char microseconds;
		} idata real_clock={10,14,2004,1,1,11,16,12,00,00,00};
		 
/*-------------------------------------------------------------
//define display character informatio table
static struct display_information 
			{
			unsigned char           lines;
			unsigned char			words;
			unsigned char			start_blink;
			unsigned char 			end_blink;
			unsigned char 			disp_addr[24];
			} xdata disp_form[2][12];*/
//-------------------------------------------------------------
//define display character code
unsigned char idata  character_code[2][32]=\
		{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},\
		 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
unsigned char idata  address_buf[24]=\
		{0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,\
		 0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef,0xef};
static struct 
	{
		unsigned char ascii;
		unsigned char stroke;
   	}code disp_strokes[]=\
		{{' ',0xcf},{'!',0xcb},{'&',0xdc},{'-',0xe7},{'.',0xe3},{'/',0xcd},{'0',0x00},{'1',0x01},\
		 {'2',0x02},{'3',0x03},{'4',0x04},{'5',0x05},{'6',0x06},{'7',0x07},{'8',0x08},\
		 {'9',0x09},{':',0xe1},{';',0xe2},{'<',0xdf},{'>',0xe0},{'?',0xcc},{'A',0x0a},\
		 {'B',0x0b},{'C',0x0c},{'D',0x0d},{'E',0x0e},{'F',0x0f},{'G',0x10},{'H',0x11},\
		 {'I',0x12},{'J',0x13},{'K',0x14},{'L',0x15},{'M',0x16},{'N',0x17},{'O',0x00},\
		 {'P',0x19},{'Q',0x1a},{'R',0x1b},{'S',0x1c},{'T',0x1d},{'U',0x1e},{'V',0x1f},\
		 {'W',0x20},{'X',0x21},{'Y',0x22},{'Z',0x23},\	 
		 };
static struct
	{
		unsigned char code_high;
		unsigned char code_low;
		unsigned char ch_stroke;
   	}code disp_ch_strokes[]=\
		{{0xb1,0xb6,0x37},{0xb3,0xf6,0x4f},{0xb5,0xad,0x3b},{0xb5,0xcd,0x52},\
		 {0xb7,0xac,0x3c},{0xb8,0xb1,0x35},{0xb8,0xcd,0x51},{0xbb,0xad,0x25},\
		 {0xbb,0xf0,0x2f},{0xbc,0xc6,0x48},{0xbd,0xf0,0x32},{0xbe,0xed,0x2a},\
		 {0xbf,0xaa,0x40},{0xbf,0xcc,0x45},{0xbf,0xda,0xb2},{0xc1,0xa6,0x50},\
		 {0xc1,0xcb,0x43},{0xc4,0xbe,0x31},{0xc4,0xea,0x2c},{0xc5,0xa8,0x3a},\	 
		 {0xc8,0xa5,0x4b},{0xc8,0xb7,0x46},{0xc8,0xcf,0x47},{0xc8,0xd5,0x2e},\
		 {0xc8,0xeb,0x4e},{0xc9,0xab,0x39},{0xc9,0xf9,0x36},{0xc9,0xfa,0x27},\
		 {0xca,0xb1,0x44},{0xca,0xbc,0x41},{0xcb,0xae,0x30},{0xcb,0xcd,0x29},\
		 {0xcb,0xd9,0x38},{0xcd,0xa3,0x4c},{0xcd,0xc1,0x33},{0xcf,0xfb,0x4a},\
		 {0xd1,0xba,0x49},{0xd2,0xf4,0x53},{0xd3,0xe8,0x3e},{0xd4,0xbc,0x3f},\
		 {0xd4,0xc2,0x2d},{0xd4,0xd9,0x26},{0xd4,0xe7,0x28},{0xd6,0xb9,0x4d},\
		 {0xd6,0xd5,0x42},{0xd6,0xf7,0x34},{0xd7,0xe9,0x3d},{0xe5,0x68,0x24},\
		 {0xfe,0xfe,0x2b}};
unsigned char code month1_dates[13]={31,31,28,31,30,31,30,31,31,30,31,30,31};
unsigned char code month2_dates[13]={31,31,29,31,30,31,30,31,31,30,31,30,31};
//-----------------------------------------------------------------------------------
//define receive buffer 

unsigned char data receive_bcc;
unsigned char data REC_ADDR;
unsigned char data receive_count;
unsigned char data disp_lines;
unsigned char data disp_words;
unsigned char data start_blink;
unsigned char data end_blink;
unsigned char data disp_count=0;
unsigned char data addr_count=0;
unsigned char data receive_buf[29];
unsigned char data receive_buf1[29];
unsigned char idata receive_buf2[29];
unsigned char bdata flag;
		sbit receive_flag=flag^0;
		sbit command=flag^1;
		sbit addr_mark=flag^2;
		sbit second=flag^3;
		sbit leap=flag^4;
		sbit change=flag^5;
		sbit black1=flag^6;
		sbit black2=flag^7;
unsigned char bdata flag1;
		sbit required=flag1^0;
		sbit close1=flag1^1;
		sbit close2=flag1^2;
		sbit closedate1=flag1^3;
		sbit closedate2=flag1^4;
		sbit oneday=flag1^5;
		sbit already=flag1^6;



//define i/o port 
		sbit osd1_cs=P1^3;
		sbit osd2_cs=P1^6;
		sbit osd_busy=P1^0;
		sbit osd_reset=P1^4;
		sbit k_4053c=P1^5;
		sbit alarm=P1^7;
		sbit sw1=P3^2;
		sbit sw2=P3^3;
		sbit AD16=P3^4;
		sbit AD17=P3^5;
//sfr          SCONF=0xbf;
//-----------------------------------------------------------------------
//define 
//void delay(void);
void system_init(void);
void monitor(void);
void detemine_command(void);
void clear_disp(void);
void timer_position(void);
void timer_setup(void);
void dot_download(void);
void write_osd(void);
unsigned char get_strokes(unsigned char);
void write_osd_date(void) ;//reentrant;
void write_osd_time(void) ;//reentrant;
unsigned char read_ds1287(unsigned char);
extern left_shift(unsigned char);
extern unsigned char take_char(unsigned int);
void create_chararter(unsigned int);
//void write_osd_cram(void);
void write_osd_vram(unsigned char,unsigned char);
void create_character(unsigned int);
void osd_control(void);
void initialize_osd(void);
void disp_character(void);
extern read_dot(unsigned int);
unsigned char get_strokes(unsigned char);
unsigned char get_ch_strokes(unsigned char,unsigned char);
void write_osd(void);
void delay(unsigned char);
void separate_half_date(void);
void separate_half_time(void);
void release_alarm(void);
void video_change(void);
void background_set(void);
void close_time(void);
void close_date(void);
unsigned long calculate_addr(unsigned char,unsigned char);
//------------------------------------------------------------------------------------------
//the main program start here
//------------------------------------------------------------------------------------------
void main()
		{
		osd_reset=0;
		delay(20);
		osd_reset=1;
		system_init();
		monitor();
		 }
//--------------------------------------------------------------------------------------
void delay(unsigned char n)
		{
			unsigned int i;
			for(i=0;i<200*n;i++)
				_nop_();
		}
		
//-----------------------------------------------------------------------------------------
void system_init(void)
		{
	//	 register unsigned char i;
	 	 TMOD=0x21;
//		 IP=0x02;       //don't set 9.8
		 SCON=0x50;
		 PCON|=0x80;
	 	 leap=1; 			//;闰年标志
		 TR1=1;
		 TH1=TL1=0xf3;
//		 TH1=TL1=0xfa;
		 TH0=0xf8;
		 TL0=0x30;
		 osd_control();
		 clear_disp();
		 IE=0x92;
		 TR0=1;
		 }
//--------------------------------------------------------------------------
void monitor(void)
		{
		 while(1)
			{
			if(receive_flag) detemine_command();
			if(!sw1) 
				{
				k_4053c=0;
				alarm=0;
				}
			else
				{
				if(!sw2) 
					{
					k_4053c=1;
					alarm=0;
					}
				}
			if(second)	
				{
				second=0;
				if(close1) osd1_cs=1;
				else       osd1_cs=0;
				if(close2) osd2_cs=1;
				else	   osd2_cs=0;
				while(osd_busy);
				write_osd_time();
				while(osd_busy);
				osd1_cs=1;
				osd2_cs=1;
				}
			if(oneday)
				{
				oneday=0;
				if(!close1)
					{
					if(closedate1) 	osd1_cs=1;
					else       		osd1_cs=0;
					}
				if(!close2)
					{
					if(closedate2) 	osd2_cs=1;
					else	   		osd2_cs=0;
					}
				while(osd_busy);
				write_osd_date();
				while(osd_busy);
				osd1_cs=1;
				osd2_cs=1;
				}
		  	}
		}

//---------------------------------------------------------------------
void osd_control(void)
		{	 
			osd1_cs=0;
			osd2_cs=0;
			left_shift(0x0e);
			while(osd_busy);
				left_shift(selectable_tv);		//normal_tv);		//display position control
			while(osd_busy);
				left_shift(disp_position_high);		//display position control
			while(osd_busy);
				left_shift(disp_position_low);
			while(osd_busy);
				left_shift(charsize);		//charater size,smooth and mask pulse control command
		   	while(osd_busy);
				left_shift(smooth);
			while(osd_busy);
				left_shift(no_background);
			while(osd_busy);
				left_shift(back_color_fring);
			delay(1);
			while(osd_busy);
				left_shift(clear_vram);
			delay(10);
 			while(osd_busy);
				left_shift(disp_control);	//display on osc on blinking 1:1 1hz
			write_osd_date();
			osd1_cs=1;
			osd2_cs=1;
			osd1_cs=0;
			osd2_cs=0;
			write_osd_time();
			while(osd_busy);
			osd1_cs=1;
			osd2_cs=1;
			osd1_cs=0;
			osd2_cs=0;
			left_shift(0x0e);
			while(osd_busy);
				left_shift(disp_position_high);		//display position control
			while(osd_busy);
				left_shift(disp_position_low);
			while(osd_busy);
				left_shift(charsize);		//charater size,smooth and mask pulse control command
		   	while(osd_busy);
				left_shift(smooth);
			while(osd_busy);
				left_shift(no_background);
			while(osd_busy);
				left_shift(back_color_fring);
			delay(1);
			while(osd_busy);
				left_shift(clear_vram);
			delay(10);
 			while(osd_busy);
				left_shift(disp_control);	//display on osc on blinking 1:1 1hz
			write_osd_date();
			osd1_cs=1;
			osd2_cs=1;
			osd1_cs=0;
			osd2_cs=0;
			write_osd_time();
			while(osd_busy);
			osd1_cs=1;
			osd2_cs=1;
 		}
				
//------------------------------------------------------------
void televisionmode(void)
	{
	unsigned char i;
	i=receive_buf[0]&0x03;
	if(i==0) 
		{
		osd1_cs=0;
		osd2_cs=0;
		}
	if(i==1) osd1_cs=0;
	if(i==2) osd2_cs=0;
	i=receive_buf[1]&0x03;
	while(osd_busy);
	left_shift(normal_tv|i);
	while(osd_busy);
	osd1_cs=1;
	osd2_cs=1;
	}
//-------------------------------------------------------------------------------
unsigned long calculate_addr(unsigned char x,unsigned char y)
		{
			unsigned long data pos;
			pos=((x-0xa1)*0x5eL+(y-0xa1))*0x20;
			return(pos);
		}
//-------------------------------------------------------------------------
void write_osd_cram(unsigned char channel)
	{
	unsigned char data i,number;
	unsigned long data pos;
//	delay(10);      //9.2
//	pointer=receive_buf[0]&0x03;             //receive_buf[0] contains command and track
	if(channel==0)	
		{
		osd1_cs=0;
		i=cram_addr;
		while(osd_busy);								//write create character addr
		left_shift(i);
		i=0x00;
		while(osd_busy);
		left_shift(i);
		for(i=0;i<32;)
			{	
			if(character_code[0][i]>0x80)
				{
				pos=calculate_addr(character_code[0][i],character_code[0][i+1]);
				number=(unsigned char)(pos>>16);
				if((number&0x01)!=0) AD16=1;
				else			     AD16=0;
				if((number&0x02)!=0) AD17=1;
				else			     AD17=0;
				create_character((unsigned int)pos);
				i++;
				i++;
				}
			else	break;
			}
		while(osd_busy);
		osd1_cs=1;
		}
	if(channel==1)		
		{
		osd2_cs=0;
		i=cram_addr;
		while(osd_busy);								//write create character addr
		left_shift(i);
		i=0x00;
		while(osd_busy);
		left_shift(i);
		for(i=0;i<32;)
			{	
			if(character_code[1][i]>0x80)
				{
				pos=calculate_addr(character_code[1][i],character_code[1][i+1]);
				number=(unsigned char)(pos>>16);
				if((number&0x01)!=0) AD16=1;
				else			     AD16=0;
				if((number&0x02)!=0) AD17=1;
				else			     AD17=0;
				create_character((unsigned int)pos);
				i++;
				i++;
				}
			else	break;
			}
	  	while(osd_busy)
		osd2_cs=1;
		}
	}
//--------------------------------------------------------------------------
void write_osd_vram(unsigned char pos,unsigned char channel)
	{
	unsigned char data i,j;
	if(channel==0) osd1_cs=0;
	else           osd2_cs=0;

⌨️ 快捷键说明

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