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

📄 单片机控制图像芯片的程序.c

📁 用单片机读写图像显示芯片SAA7114H的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************
*	单片机控制程序   0.1版
*
*	日期:2005.11
	设计:保密
	功能:接收红灯信号、车辆线圈信号,给图象卡控制信号,读入时间信息等	
********************************************************************************/
//#define debug	//是否需要设定时间

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <absacc.h>
#include <intrins.h>

//#include ".\inc\saa7114.H"
#include ".\inc\STC89C51RC_RD_PLUS.H"
//#include <err.h>

//**********图象卡常量区**********************
#define MTD  30H	//主发送缓冲区首址
#define SLA  50H	//寻址字节存放单元
#define NUM  51H	//传送字节数据存放单元
#define HADD 53H	//状态处理模块页定位地址存放单元
#define INBUF_LEN 2   //串口接受数据长度

#define Self_Define_ISP_Download_Command    0x22
#define SAA_7114_NTSC_HSYNC_START  (-17)
#define SAA_7114_NTSC_HSYNC_STOP   (-32)

#define SAA_7114_PAL_HOFFSET            (2)
#define SAA_7114_PAL_VOFFSET            (10)
#define SAA_7114_PAL_WIDTH              (720)
#define SAA_7114_PAL_HEIGHT             (300)

#define LOBYTE(x) ((unsigned char)((x) & 0xff))
#define HIBYTE(x) ((unsigned char)(((x) >> 8) & 0xff))
#define LOWORD(x) ((unsigned short int)((x) & 0xffff))
#define HIWORD(x) ((unsigned short int)(((x) >> 16) & 0xffff))

/*
nRESET=
SDA1=MCU_P1.1
SCL=MCU_P1.0
CAPSTR_V1=MCU_P1.2
CS_V1=CPU_PC12
CAPING_V1=MCU_P0.4
nRESET
CAP
NRD=CPU_NRD
*/

#define  _Nop()  _nop_()        /*定义空指令*/
#define  uchar unsigned char  /*宏定义*/
#define  uint  unsigned int

#define time_LEN 7  //定义发送数据长度

unsigned char recv_9200_buf[3];

unsigned char timebuf_BCD[time_LEN]={0,0,10,28,7,5,6};	//时间缓冲区
	/*
	设置时钟数据地址 格式为: 		秒    分   时   日   月   周	年
			    7Byte (BCD码)		1B    1B   1B   1B   1B   1B	1B		
	*/
	
unsigned char code saa7114_init_data[] = {
	0x00,		/* 00 - ID byte , chip version, read only */
	0x08,		/* 01 - X,X,X,X, IDEL3 to IDEL0 - horizontal increment delay,recommended position */
	0xc1,		/* 02 - FUSE=3, GUDL=2, MODE=1 ;input control */
	0x10,		/* 03 - HLNRS=0, VBSL=1, WPOFF=0,HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
	0x90,		/* 04 - GAI1=256 */
	0x90,		/* 05 - GAI2=256 */			0xeb,0xe0,
//	SAA_7114_NTSC_HSYNC_START,	/* 06 - HSB: hsync start,depends on the video standard */
//	SAA_7114_NTSC_HSYNC_STOP,	/* 07 - HSS: hsync stop, depends on the video standard */
	/*0xb8,*/0x98,		/* 08 - AUFD=1, FSEL=1, EXFIL=0, VTRC=1,HPLL: free running in playback, locked in capture, VNOI=0 */
	/*0x80,*/	0x40,		/* 09 - BYPS=0, PREF=0, BPSS=0, VBLB=0, UPTCV=0, APER=1; depends from input */
	0x80,		/* 0a - BRIG=128 ------------------------------------------------------------ */
	0x44,		/* 0b - CONT=1.109----------------------------------------------------------  */
	0x40,		/* 0c - SATN=1.0-----------------------------------------------------  */
	0x00,		/* 0d - HUE=0 --------------------------------------------------------- */
	0x81,		/* 0e - CDTO, CSTD2 to 0, DCVF, FCTC, CCOMB; depends from video standard */
	0x2a,		/* 0f - ACGC,CGAIN6 to CGAIN0; depends from video standard */
	0x06,		/* 10 - OFFU1 to 0, OFFV1 to 0, CHBW, LCBW2 to 0 */
	0x00,		/* 11 - COLO, RTP1, HEDL1 to 0, RTP0, YDEL2 to 0 */
	0x5c,		/* 12 - RT signal control RTSE13 to 10 and 03 to 00 */
	0xc0,		/* 13 - RT/X port output control *********** */
	0x48,		/* 14 - analog, ADC, compatibility control */
	0x11,		/* 15 - VGATE start FID change  */
	0xfe,		/* 16 - VGATE stop */
	0x00,		/* 17 - Misc., VGATE MSBs */
	0x40,		/*18 RAWG */
	0x80,		/* 19 RAWO */
	0x00,/* 1a RAWO */
	0x00,/* 1b RAWO */
	0x00,/* 1c RAWO */
	0x00,/* 1d RAWO */
	0x00,/* 1e RAWO */
	0x00,		/*1f status byte, read only */
	0x00,		/* 20 video decoder reserved part */
	0x00,/* 21 RAWO */
	0x00,
	0x00,/*  RAWO */
	0x00,/* 24 */
	0x00,/*  */
	0x00,/*  */
	0x00,/*  */
	0x00,/*  */
	0x00,/*  */
	0x00,/* 2a */
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,		/*30 audio clock generator */
	0x72,
	0x03,		//32
	0x00,
	0xcd,
	0xcc,	//35
	0x3a,
	0x00,
	0x03,	//38
	0x20,	//39
	0x00,	//  3a
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,	// 3f
	0x00,//40	/* VBI data slicer */
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,
	0xff,//57
	0x00,		// 58 framing code ------------------------------------------------------------------ */
	0x47,		// 59 horizontal offset
	0x03,		// 5a vertical offset
	0x03,		// 5b field offset
	0x00,		// 5c reserved
	0x3e,		// 5d header and data
	0x00,		// 5e sliced data
	0x00,		// 5f reserved
	0x00,		/* 60 video decoder reserved part */
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,	// 70  video decoder reserved part
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,	//7f
	0x10,		// 80 X-port, I-port and scaler ,now i enable task A
	0x00,	//81H
	0x00,	//82H
	0x01,	//83H
	0x00,	//84H
	0x00,	// 85 hsync and vsync ? 
	0x45,
	0x10,	//87,开机的时候禁止HPROT IPORT输出
	0xf0,	//88
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,	//8e
	0x00,	//8f
	0x00,	//90 Task A definition
	0x08,	//91  Scaler input source is data from decoder
	0x10,
	0x40,	//93   Dwords are transferred 16-bit word wise via IPD and HPD, see subaddress 85h bits ISWP1 and ISWP0
	0x10,	// 94 window settings
	0x00,
	0xd0,	//96	horizontal input 720
	0x02,	//with 0x96
	0x0a,	//98
	0x00,
	0xf2,	//9a
	0x00,	//9b
	0x80,	//9c output windows size 384 with 0x9d
	0x01,	//9d  output windows size 384
	0x20,	//Vertical output windows size 288 with 0x9f
	0x01,	//Vertical output windows size 288
	0x01,	///a0 horizontal integer prescaling ratio
	0x00,	//a1 水平方向预缩放, accumulation sequence length
	0x00,	//a2  UV FIR filter, Y FIR filter, prescaler DC gain
	0x00,
	0x80,	//a4  亮度 brightness------------------------------------------------*/	
	0x40,	// a5 亮度增益------------------------------------------------------*/
	0x40,	// a6 色度饱和
	0x00,
	0xaa,	//a8  horizontal luminance scaling increment
	0x03,
	0x00,	//aa horizontal luminance phase offset
	0x00,
	0xd5,	// horizontal chrominance scaling increment
	0x01,	//ad
	0x00,	// horizontal chrominance phase offset
	0x00,
	0x00,	// b0 vertical luminance scaling increment
	0x04,
	0x00,	//b2  vertical chrominance scaling increment
	0x04,//b3
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,//b8
	0x00,//b9
	0x00,//ba
	0x00,
	0x00,//bc
	0x00,//bd
	0x00,//be
	0x00,//bf
	0x00,		//c0  Task B definition
	0x08,		//c1
	0x10,		//c2
	0x40,		//c3
	0x10,		//c4 window settings
	0x00,
	0xd0,
	0x02,		//c7
	0x0a,
	0x00,
	0x20,		//ca
	0x01,
	0xd0,		//cc
	0x02,		//cd
	0x20,		//ce
	0x01,		//cf 
	0x01,		// d0 horizontal integer prescaling ratio
	0x00,		//d1 horizontal prescaler accumulation sequence length
	0x00,		//d2 UV FIR filter, Y FIR filter, prescaler DC gain
	0x00,
	0x80,		//d4  luminance brightness
	0x42,		// d5 luminance gain
	0x42,		// d6 chrominance saturation
	0x00,
	0x00,		//d8 horizontal luminance scaling increment
	0x04,
	0x00,		//da  horizontal luminance phase offset
	0x00,
	0x00,		//dc  horizontal chrominance scaling increment 
	0x02,		//dd
	0x00,		// de horizontal chrominance phase offset
	0x00,
	0x00,		// e0 vertical luminance scaling increment
	0x04,
	0x00,		// e2  vertical chrominance scaling increment
	0x04,		//e3
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00,
	0x00
};//时钟是LLC,同步是RTS0、RTS1或者XPH,XPV帧参考一般不用。

unsigned char checksum,bit_count=0;

bit read_flag=0;


bit wire0_flag_cycle=0;
bit wire1_flag_cycle=0;
bit wire2_flag_cycle=0;
bit wire3_flag_cycle=0;

sbit T_CLK= P0^7; /*实时时钟时钟线引脚 */
sbit T_IO=	P1^6; /*实时时钟数据线引脚 */
sbit T_RST= P1^5; /*实时时钟复位线引脚 */
sbit ACC0 =	ACC^0;
sbit ACC7 =	ACC^7;

//=======定义单片机与图像卡连接信号============
sbit CAPSTR_V1=P1^2;// 1号卡开始捕捉
sbit CAPSTR_V2=P3^6;// 2号卡开始捕捉

sbit CAPING_V1=P2^0;// 1号卡正在捕捉
sbit CAPING_V2=P2^1;// 2号卡正在捕捉

sbit CS_V2=P3^5;

sbit SDA=P3^7;
sbit SCL=P0^6;

//=======定义线圈输入与红灯输入的端口
sbit INPUT_SEL1=P1^1;
sbit INPUT_SEL3=P1^3;
sbit INPUT_SEL4=P1^0;

sbit ch0=P2^0;
sbit ch1=P2^1;
sbit ch2=P2^2;
sbit ch3=P2^3;
sbit ch4=P2^4;
sbit ch5=P2^5;
sbit ch6=P2^6;
sbit ch7=P2^7;

void iic_start(); 
void iic_stop(); 
void send_ack(); 
void nsend_ack(); 
void check_ack(); 
void write_byte(unsigned char shu); //发送一个数据字节
void write_byte0();
void write_byte1();
unsigned char read_byte(); //7--读取一个字节
void delay_nop(unsigned char step); //单步延时子程序
void write_N_byte(unsigned char CS_I2C,unsigned char ic_addr,unsigned char send_data[],unsigned char number);
void write_ONE_byte(unsigned char CS_I2C,unsigned char ic_addr,unsigned char send_data);
void read_N_byte(uchar CS_I2C,uchar ic_addr,uchar incept_data[],uchar number); //接收N个字节 CS_I2C为读寻址字节
void write_bytea(uchar CS_I2C,uchar temp[],uchar n); //10-写第N个字节
void RTInputByte(unsigned char);       //输入1Byte
unsigned char  RTOutputByte(void);       //输出1Byte
void	W1302(unsigned char, unsigned char);
unsigned char  R1302(unsigned char);
void	Set1302(unsigned char *);         //设置时间
void	Get1302(unsigned char curtime[]); //读取1302当前时间
void	sendtime(void);

#include ".\inc\i2c.h"

void init_serialcomm(void)
{
    SCON  = 0x50;       //SCON: serail mode 1, 8-bit UART, enable ucvr 
    TMOD |= 0x20;       //TMOD: timer 1, mode 2, 8-bit reload 
    PCON |= 0x80;       //SMOD=1    POF=0
    TH1   = 0xFF;       //Baud:115200  fosc=22.1184MHz
    IE   |= 0x90;       //Enable Serial Interrupt
    TR1   = 1;          // timer 1 run 
}

//向串口发送一个字符,以16进制显示
void send_char_com_hex(unsigned char ch)  
{
	int i;
	SBUF='[';
	
	while(TI==0);
	TI=0;

	i=(ch>>4)&0x0f;
	i+=48;
	if(i>57)i+=7;
	SBUF=i;
	while(TI==0);
	TI=0;		

	i=ch&0x0f;
	i+=48;
	if(i>57)i+=7;
	SBUF=i;
	while(TI==0);
	TI=0;

	SBUF=']';
	while(TI==0);
	TI=0;
	
}

//向串口发送一个字符 
void send_char_com(unsigned char ch)  
{
    SBUF=ch;
    while(TI==0);
    TI=0;
}

//向串口发送一个字符串,strlen为该字符串长度 
void send_string_com(unsigned char *str,unsigned int strlen)
{
    unsigned int k=0;
    do
    {
        send_char_com(*(str + k));
        k++;
    } while(k < strlen);
}

void serial() interrupt 4 using 3 	//串口接收中断函数
{
	unsigned char ch=0;
	if(RI)
	{
		ch=SBUF;		
//------------------------------------------------下载用户程序		
		if(ch==Self_Define_ISP_Download_Command)        //是自定义下载命令
        {
            delay_nop(60);    //延时1秒就足够了
            delay_nop(60);    //延时1秒就足够了
            delay_nop(60);    //延时1秒就足够了			

⌨️ 快捷键说明

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