📄 main.c
字号:
/****************************************************************/
/* */
/* TW9910 Evaluation Board */
/* */
/* CPU : W78E516BP */
/* LANGUAGE : Tasking-C 5.0 */
/* PROGRAMMER : */
/* Modify : Bean */
/****************************************************************/
/*
01/05/2004 : - remove led function
- add an osd display function when changing mux
02/10/2004 : - add interface fuction with window of pc
06/06/2005 : - add tw9910 main board firmware.
*/
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "main.h"
#include "tw99.h"
#include "i2c.h"
#include "printf.h"
#include "osd.h"
#include "remo.h"
#include "ttext.h" // for teletext
bit PAL_NTSC, Last_PAL_NTSC;
bit DetVideo, OldDetAuto;
bit DetFF=0;
bit DetInterace; //
bit Flashing=1; // LED status
bit ColorBar=0; // Test Pattern Off
bit CCFlag=0; // CC On flag
bit RestLValue;
bit NotDefineID = 0;
bit OneTimeCaptionCtr;
//bit OldCCFlag;
bit IndOSD;
bit I2CInitialBlocking = 1;
bit ReverseUpDownKey;
bit ReturnValue = 0;
bit KeyOn;
bit GateET;
bit MaskKey;
bit IntFlag = 0;
bit OldBypassKey;
bit MaskScaleMode = 0;
bit OldMaskScaleMode = 0;
#ifdef TEST_SERCOM
bit MaskEcho = 0;
DATA BYTE StoreArg1, StoreArg2;
DATA BYTE AddressOffset = 0;
#endif //TEST_SERCOM
DATA BYTE ChipID;
DATA WORD tm01=0;
DATA WORD tm001=0;
DATA BYTE tic02=0;
DATA BYTE tic01=0;
DATA BYTE I2CAddressDeb = TW99I2CAddress;
DATA BYTE DetChangeColorSystem = 0;
DATA BYTE DetChangeInterace = 0;
DATA BYTE MenuLayer, MenuIndex ,OldP0;// ,OneMenuIndex;
//DATA BYTE LcdAddress , LcdData;
DATA BYTE OneMenuIndex;
DATA BYTE TwoMenuIndex;
DATA BYTE EncoderID;
DATA BYTE StatusReg1;
DATA BYTE OldDetVlock;
DATA BYTE VDelayReg;
DATA BYTE SelectedSW;
DATA BYTE OldKeyState;
DATA BYTE OldMenuLayer;
DATA BYTE OldMenuIndex;
DATA BYTE MaxMenuIndex;
DATA BYTE OSDData;
DATA BYTE OldOSDData;
DATA BYTE MaxMenuLayer;
DATA BYTE KeyState;
DATA BYTE TargetID;
DATA BYTE ThreeMenuIndex;
DATA BYTE OsdErasingTime;
DATA BYTE StayKey;
DATA BYTE VcrFFNo = 0;
//===================== Serial ============================================
#define BUF_MAX 10
static DATA BYTE RS_buf[BUF_MAX];
static DATA BYTE RS_in=0, RS_out=0;
bit RS_Xbusy=0; // bit RS_Xbusy=0;
//================== Debug key input ======================================
#define MaxBuf 17 // 1+sp+2+sp+2+sp+2+sp+2+sp+2+dum =17
#define MaxArg 6 //
static PDATA BYTE commdbuf[MaxBuf], commdptr, bptr;
static PDATA BYTE arg[MaxArg], argn;
DATA BYTE InSel = 0, OutSel = 0;
//===================== Remocon ==========================================
#ifdef REMO_NEC
static bit RemoPhase=0;
static PDATA BYTE RemoStep=0;
static PDATA BYTE RemoHcnt, RemoLcnt, RemoData[4];
static IDATA BYTE RemoDataReady=0;
static IDATA BYTE RemoNum, RemoBit;
static IDATA BYTE RemoDataCode=0xff;
#endif
//===================== Teletext =========================================
#ifdef SUPPORT_TELETEXT
IDATA BYTE ReData[5] = {0xff, 0xff, 0xff, 0xff, 0xff};
IDATA BYTE RepRemoNo = 0;
IDATA BYTE TTToggle = 0x00;
bit TeleTextStatus = 0;
#endif //SUPPORT_TELETEXT
//========================================================================
CODE_P BYTE *ptr_NTSC, *ptr_PAL, *ptr_ENC_NTSC, *ptr_ENC_PAL;
#include "Table.c"
//=============================================================================
// Remocon
//=============================================================================
#ifdef REMO_NEC
void EnableRemoconInt(void)
{
RemoDataReady = 0;
IE = IE | 0x04; // Enable Remocon (Enable Ext int1)
// IntFlag = 1;
}
void DisableRemoconInt(void)
{
IE = IE & 0xfb; // Disable Remocon (Disable Ext int1)
}
void InitForRemo(void)
{
WORD temp;
temp = 0x10000 - 173; // 187.71us = 1.085*173
RCAP2H = TH2 = temp>>8;
RCAP2L = TL2 = (BYTE)(temp & 0xff);
TR2 = 1;
tm001 = 0;
RemoStep = 0;
RemoPhase = 0;
RemoHcnt = 0;
RemoLcnt = 0;
}
void ClearRemoTimer(void)
{
TR2 = 0;
}
#endif
/*****************************************************************************/
/* Ext Int 0 Interrupt */
/*****************************************************************************/
//_interrupt(0) void ext1_int (void)
INTERRUPT(0, ext0_int)
{
EX0 = 0;
}
//****************************************************************************
// Ext Int 1 Interrupt
//****************************************************************************
#ifdef REMO_NEC
INTERRUPT(2, remocon_int)
{
DisableRemoconInt();
InitForRemo();
}
#endif
/*****************************************************************************/
/* Timer 0 Interrupt */
/*****************************************************************************/
INTERRUPT(1, timer0_int)
{
// static DATA BYTE buf;
tm01++;
if( tm01 > 48 ){
tm01 = 0;
tic01++;
if((tic01 == 0xff) && (OsdErasingTime != 0x00))
OsdErasingTime--;
#ifdef DEBUG_REPKEY
if(tic02 < 0xff)
tic02++;
#endif //DEBUG_REPKEY
}
}
/*****************************************************************************/
/* Timer 1 Interrupt */
/*****************************************************************************/
INTERRUPT(5, timer2_int)
{
TF2 = 0; // clear overflow
tm001++;
#ifdef REMO_NEC
{
if( RemoDataReady ) return;
switch( RemoStep ) {
case 0:
if( P3_3==0 ) {
RemoLcnt++;
if( RemoLcnt==0xff ) goto RemoError;
IntFlag = 1;
}
else {
RemoHcnt = 0;
RemoStep++;
}
break;
case 1:
if( P3_3==1 ) {
RemoHcnt++;
if( RemoHcnt==0xff ) goto RemoError;
}
else {
if( RemoLcnt>=15*3 && RemoLcnt<=17*3 ) { // $$High Leader Code length
if( RemoHcnt>=3*3 && RemoHcnt<=5*3 ) { // $$Low Leader Code length
RemoStep = 3;
RemoDataReady = 2;
break;
}
else if( RemoHcnt>=7*3 && RemoHcnt<=9*3 ) { // $$Low Leader Code length
RemoStep++; // $$Initial
RemoPhase = 0;
RemoLcnt = 0;
RemoNum = 0;
RemoBit = 0;
break;
}
}
else goto RemoError;
}
break;
case 2: // $$Custom Code and Data
if( RemoPhase==0 ) {
if( P3_3==0 ) // Phase=0 Input=0
RemoLcnt++;
else { // Phase=0 Input=1
RemoPhase = 1;
RemoHcnt = 0;
}
}
else {
if( P3_3==1 ) // Phase=1 Input=1
RemoHcnt++;
else { // Phase=1 Input=0
RemoPhase = 0;
if( RemoLcnt>=1 && RemoLcnt<=5 ) {
if( RemoHcnt<=2*3 ) // bit 0
RemoData[RemoNum] <<= 1;
else if( RemoHcnt<=4*3 ) { // bit 1
RemoData[RemoNum] <<= 1;
RemoData[RemoNum]++;
}
else goto RemoError;
if( ++RemoBit>=8 ) {
RemoBit = 0;
if( ++RemoNum>=4 ) {
RemoDataReady = 1;
RemoStep++;
}
}
RemoLcnt = 0;
}
else goto RemoError;
}
}
break;
case 3:
break;
}
return;
RemoError:
ClearRemoTimer(); //TimerFor208us();
EnableRemoconInt();
}
#endif // REMO_NEC
}
void delay(BYTE cnt)
{
BYTE t;
if( !cnt ) return;
t = tic01 + cnt;
while( tic01 != t );
}
//****************************************************************************/
// Serial Interrupt
//****************************************************************************/
INTERRUPT(4, serial_int)
{
if( RI ) { //--- Receive interrupt ----
RI = 0;
RS_buf[RS_in++] = SBUF;
if( RS_in>=BUF_MAX ) RS_in = 0;
}
if( TI ) { //--- Transmit interrupt ----
TI = 0;
RS_Xbusy=0;
}
}
//=============================================================================
// Serial RX Check
//=============================================================================
BYTE RS_ready(void)
{
if( RS_in == RS_out ) return 0;
else return 1;
}
//=============================================================================
// Serial RX
//=============================================================================
BYTE RS_rx(void)
{
BYTE ret;
ES = 0;
ret = RS_buf[RS_out];
RS_out++;
if(RS_out >= BUF_MAX)
RS_out = 0;
ES = 1;
return ret;
}
//=============================================================================
// Serial TX
//=============================================================================
void RS_tx(BYTE tx_buf)
{
while(1) {
if(!RS_Xbusy) {
SBUF = tx_buf;
RS_Xbusy=1;
break;
}
}
}
/*===========================================================================*/
/* Initialize CPU */
/*===========================================================================*/
void InitCPU(void)
{
/*----- Initialize interrupt -------------*/
TH1 = 0xff; // SMOD = 0 SMOD =1
// 0ffh :57600 bps
// 0fdh : 9600 bps 0fdh :19200 bps
// 0fah : 4800 bps
// 0f4h : 2400 bps
// 0e8h : 1200 bps
SCON = 0x50; // 0100 0000 mode 1 - 8 bit UART
// Enable serial reception
TMOD = 0x22; // 0010 0010 timer 0 - 8 bit auto reload
// timer 1 - baud rate generator
TCON = 0x55; // 0101 0001 timer 0,1 run
// int 0, edge triggered
// int 1, edge triggered
// TF1 TR1 TF0 TR0 EI1 IT1 EI0 IT0
TH0 = TL0 = 64; // 64=4608 Hz at 11.0592MHz
PCON = 0x80; // 0000 0000 SMOD(double baud rate bit) = 1
IP = 0x02; // 0000 0000 interrupt priority
// - - PT2 PS PT1 PX1 PT0 PX0
IE = 0x92; // 1001 0010 interrupt enable:Serial,TM0
// EA - ET2 ES ET1 EX1 ET0 EX0
TI = 1; // LJY000724 // For Starting Serial TX
ES = 1; // LJY000724
//------------ Timer 2 for Remocon --------------------------------
T2CON = 0x00; // Timer2 Clear
TR2 = 0;
ET2 = 1;
//-----------------------------------------------------------------
#ifdef REMO_NEC
RemoDataReady = 0;
#endif //REMO_NEC
CHPENR = 0x87; // Enable AUX RAM in Winbond(W78E516B)
CHPENR = 0x59; //
CHPCON = 0x10; //
CHPENR = 0x00; // Write Disable
}
/*===========================================================================*/
/* New Line */
/*===========================================================================*/
void NewLine(void)
{
Puts("\r\n");
}
void PutsP(PDATA_P BYTE *ptr)
{
BYTE ch;
while(*ptr!='\0') {
ch = *ptr++;
RS_tx(ch);
}
}
/*===========================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -