📄 __main.c
字号:
//===================================================================//
// Project Name : ZBoard
// Module Name : Master Firmware Program
// Product Type : License
// OS/Dev Tool : AT89C52, uVision 2
// Original Author : Ray Yang
// Organization : YBWork.com
// Original Date : July, 25, 2001
// Addr : Room 402, No. 131, Meilong No. 9
// TEL : 86-21-54630718
// EMail : rayyang2000@yahoo.com
// Website : http://www.ybwork.com
// Copyright : Copyright (L) YBWork.com, 2001
// Comments :
//
// << History >>
// July, 25, 2001 The first release
//===================================================================//
#include "HAL.H"
#include "USBD12.H"
#include "ZBoard.h"
#include "USB110.H"
#include "USB.H"
#include "CHAP9.H"
#include "VDOR.H"
#include "FLASH.H"
#ifdef MONITOR51 /* Debugging with Monitor-51 needs */
char code reserve [3] _at_ 0x23; /* space for serial interrupt if */
#endif /* Stop Exection with Serial Intr. */
/* is enabled */
extern unsigned char idata GenBuf[GENBUF_LENGH];
///////////////////////////////////
// Data definition
ZBOARDFLAGS bdata bZBoardFlags;
extern CONTROL_XFER ControlData;
extern CODE_DATA idata CodeData;
///////////////////////////////////
/////////////////////////////////////////////////
// Useless function for disable Warning L16
/////////////////////////////////////////////////
/* Configure Timer 0
- Mode = 1
- Interrupt = ENABLED
- Clock Source = INTERNAL
- Enable Gating Control = DISABLED
*/
void Init_Timer0(void)
{
TMOD &= 0xF0; /* clear Timer 0 */
TMOD |= 0x1;
TL0 = 0x0; /* value set by user */
TH0 = 0x0; /* value set by user */
ET0 = 1; /* IE.1*/
TR0 = 1; /* TCON.4 start timer */
// PT0 = 1;
}
/* Interrupt Control Unit */
/* **** Enabled interrupts in Interrupt Enable Register ****
**** GLOBAL INTERRUPT MUST BE ENABLED FOR ANY OTHER
**** INTERRUPT TO WORK!
*/
/* GLOBAL INTERRUPT DISABLED ALL INTERRUPTS
ARE DISABLED */
/* External interrupt 0 */
/* Priority Level = 0 */
/* Timer 0 interrupt */
/* Priority Level = 0 */
void Init_SpecialInterrupts(void)
{
IT0 = 0;
EX0 = 1;
// PX0 = 0;
}
void Init_Port()
{
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
}
/*Serial Port */
/*Mode = 1 /8-bit UART
Serial Port Interrupt = Disabled */
/*Receive = Enabled */
/*Auto Addressing = Disabled */
void Init_COMM(void)
{
SCON = 0x52;
PCON = 0x80 | PCON;
TMOD = 0x21;
// TCON = 0x69; /* TCON */
TH1 = 0xfa; // 9600bps @ 11.0592MHz
TR1 = 1;
ES = 1;
}
/*------------------------------------------------
The main C function. Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void)
{
#ifdef _DEBUG
unsigned char key;
unsigned short i;
#endif
/*------------------------------------------------
Setup the serial port for 1200 baud at 16MHz.
These codes are used for MON51
------------------------------------------------*/
#ifndef MONITOR51
// SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
// TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
// TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
// TR1 = 1; /* TR1: timer 1 run */
// TI = 1; /* TI: set TI to send first char of UART */
#endif
Init_Timer0();
Init_SpecialInterrupts();
Init_Port();
Init_COMM();
IO_LED = 0;
bZBoardFlags.bits.bLED = LED_ON;
USB_Reconnect();
#ifdef _DEBUG
printf("\n\nZBoard USB Master Program Ver 0.01. Written by Ray Yang. rayyang2000@yahoo.com\n");
printf("Waiting for interrupt event...\n");
#endif
ENABLE_INTERRUPTS;
EX0 = 1;
/*------------------------------------------------
Note that an embedded program never exits (because
there is no operating system to return to). It
must loop and execute forever.
------------------------------------------------*/
/* Main program loop */
while(TRUE)
{
#ifdef _DEBUG
if(RI)
{
key = _getkey();
switch(key)
{
case 'i':
if(bZBoardFlags.bits.bControl_State == USB_IDLE)
printf("Control state = USB_IDLE.");
else if(bZBoardFlags.bits.bControl_State == USB_RECEIVE)
printf("Control state = USB_RECEIVE.");
else if(bZBoardFlags.bits.bControl_State == USB_TRANSMIT)
printf("Control state = USB_TRANSMIT.");
printf(" ControlData.wCount = %x.\n", ControlData.wCount);
printf("Endpoint 4 (Bulk Out) Status = %bx, Endpoint 5 (Bulk In) Status = %bx.\n",
USBD12_ReadEndpointStatus(4), USBD12_ReadEndpointStatus(5));
if(bZBoardFlags.bits.bDMA_State == DMA_IDLE)
printf("DMA_State = DMA_IDLE.\n");
else if(bZBoardFlags.bits.bDMA_State == DMA_RUNNING)
printf("DMA_State = DMA_RUNNING.\n");
else if(bZBoardFlags.bits.bDMA_State == DMA_PENDING)
printf("DMA_State = DMA_PENDING.\n");
printf("Last Device Request: bmRequestType = 0x%bx, bRequest= 0x%bx, wValue = 0x%x, wLength = 0x%x, wIndex = 0x%x.\n",
ControlData.DeviceRequest.bmRequestType,
ControlData.DeviceRequest.bRequest,
ControlData.DeviceRequest.wValue,
ControlData.DeviceRequest.wLength,
ControlData.DeviceRequest.wIndex);
printf("Data: ");
for(i = 0; i < ControlData.DeviceRequest.wLength; i ++)
printf("0x%bx, ", *((ControlData.dataBuffer)+i));
printf("\n");
break;
case '\r':
USB_Reconnect();
break;
case 'v':
if(bZBoardFlags.bits.bVerbose == 0)
{
printf("Verbose Mode = ON.\n");
DISABLE_INTERRUPTS;
bZBoardFlags.bits.bVerbose = 1;
ENABLE_INTERRUPTS;
}
else
{
printf("Verbose Mode = OFF.\n");
DISABLE_INTERRUPTS;
bZBoardFlags.bits.bVerbose = 0;
ENABLE_INTERRUPTS;
}
break;
case 'l':
IO_LED ^= 1;
break;
default:
break;
}
}
#endif
if (bZBoardFlags.bits.bBus_Reset)
{
DISABLE_INTERRUPTS;
bZBoardFlags.bits.bBus_Reset = 0;
ENABLE_INTERRUPTS;
// Release D12's SUSPEND pin after bus reset
D12SUSPD = 1;
} // if bus reset
if (bZBoardFlags.bits.bSuspend)
{
DISABLE_INTERRUPTS;
bZBoardFlags.bits.bSuspend= 0;
ENABLE_INTERRUPTS;
} // if suspend change
if (bZBoardFlags.bits.bSetup_Packet)
{
DISABLE_INTERRUPTS;
bZBoardFlags.bits.bSetup_Packet = 0;
ENABLE_INTERRUPTS;
USB_Control_Handler();
D12SUSPD = 1;
} // if setup_packet
} // Main Loop
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -