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

📄 video.c

📁 使用AVR单片
💻 C
字号:
//atmega16-16pi 
//12Mhz 
//同步端:D.1 + 二极管(in4148) + 1000 欧-----
//											  |----75欧----地
//视频端:D.0 + 二极管(in4148) + 330 欧------
 
#include <avr/io.h> 
#include <avr/signal.h>
#include <avr/interrupt.h> 
#include <avr/sleep.h>
#define uchar unsigned char 
#define uint unsigned int 
#include "Picture.h" 
#define led_run;      PORTA^=(1<<6);   //VIOED LED 

uchar syncON, syncOFF;                  //行同步 
uchar v1, v2, v3, v4, v5, v6, v7, v8;      //显示行数据 
uint volatile LineCount; 
uint volatile Count;
uchar volatile framecount;                     //帧计数 
uchar  flashcount;                     //画面计数 
uchar screen[800];                     //画面缓存 

#define lineTime 762                   //1行=1000000/25/625 US *12MHZ-1 
#define ScreenTop 80//40                  //定义显示区域顶行 
#define ScreenBot 240                  //定义显示区域底行 

void Display(void);

SIGNAL(SIG_OUTPUT_COMPARE1A)
{ 
	PORTD = syncON;     
	LineCount ++ ;   
	if (LineCount==298)
	{ 
		syncON = 0x02;
		syncOFF = 0;
	}
	if (LineCount==301)	
	{
		syncON = 0;
		syncOFF = 0x02;
	}  
	if (LineCount==313) 
	{
		LineCount = 1;
		Count = 0;
	} 
	PORTD = syncOFF; 
} 

int main(void) 
{ 
	cli();

    DDRA = 0xff; 

    PORTD = 0; 
    DDRD = 0xff; 
	OCR1A = lineTime;
	TCCR1B = 8;
	TCCR1A = 0x00;
	TIMSK = 0x10;

	LineCount = 1; 
	framecount=0; 
	flashcount=0; 
	syncON = 0B00000000;
	syncOFF = 0B00000010;
	//initialize画面缓存 
/*    for (i=0;i<=799;i=i+1) 
    {
		screen[i]=zk1[0][i];
	}*/
	sei(); 
	sbi(TCCR1B,CS10);
	while(1) 
	{ 
      //precompute pixel index for next line 
	/*	if ((LineCount<ScreenBot) && (LineCount>=ScreenTop)) 
		{ 
         //left-shift 3 would be individual lines 
         // <<2 means line-double the pixels 
         //<<2使2行像素显示相同的信息 
         i=(LineCount-ScreenTop)<<2 & 0xfff8; //(0-199)<<2 
		} */
      //stall here until next line starts 
      //sleep enable; mode=idle 
      //使用休眠使进入同步中断入口时间统一 
		set_sleep_mode(SLEEP_MODE_IDLE);
		sleep_mode();
		led_run; 
      //Put code here to execute once/line 
      //During the active portion of a line; 
      //--TCNT1 goes from about 130 to about 480 
      //--Usable lines 1 to about 240 
      //注意:以下代码每行执行一次,且时序严格,视频间隔相同 
		if ((LineCount<ScreenBot) && (LineCount>ScreenTop)) 
		{ 
			uchar Temp;
			for(Temp = 10; Temp !=0;Temp--)
				cbi(PORTD,0);
			
		//	for(Temp = 5; Temp != 0; Temp--)
		//		sbi(PORTD,0);
				/*
			for(Temp = 10; Temp !=0;Temp--)
			if((LineCount < 50))
				sbi(PORTD,0);
			else 
				cbi(PORTD,0);
			
			for(Temp = 5; Temp != 0; Temp--)
				sbi(PORTD,0);
			cbi(PORTD,0);*/
			{
				v1 = pgm_read_byte(HanZi + Count); Count ++;
				v2 = pgm_read_byte(HanZi + Count); Count ++;
				v3 = pgm_read_byte(HanZi + Count); Count ++;
				v4 = pgm_read_byte(HanZi + Count); Count ++;
				v5 = pgm_read_byte(HanZi + Count); Count ++;
				v6 = pgm_read_byte(HanZi + Count); Count ++;
				v7 = pgm_read_byte(HanZi + Count); Count ++;
				v8 = pgm_read_byte(HanZi + Count); Count ++;
				if(v1 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v1 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v2 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v3 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v4 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v5 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v6 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v7 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B10000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B01000000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B00100000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B00010000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B00001000){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B00000100){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B00000010){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				if(v8 & 0B00000001){asm("sbi 0x12,0"::);}else{asm("cbi 0x12,0"::); }
				asm("cbi 0x12,0"::);
			}
		} 

/*		if (framecount>=100) 
		{ 
			framecount=0; 
			flashcount++; 
			if(flashcount>=9){flashcount=0;} 
			for (i=0;i<=799;i=i+1) 
			{ 
				screen[i]=zk1[flashcount][i]; 
			} 
		}*/
   }
}

⌨️ 快捷键说明

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