?? 單片機控制圖像芯片的程序.c
字號:
/********************************************************************************
* 單片機控制程序 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 + -