📄 avr2560_usb.c
字号:
//###
//### AVR 2560 烹钦 Board Sample Code.
//###
//### 俺惯: 茄惫哪腔磐厚怜 磊悼拳 扁贱评
//### 扁贱评厘 炔犁篮
//###
//### 老磊: 2009斥 2岿 16老
//###
//### 沥焊: www.hcvelec.com
//###
#include <avr/io.h>
#include <avr/iom2560.h>
#include <stdio.h>
#include <avr/delay.h>
#include "global.h"
#include "uart.h"
#include "../../avrlib/buffer.h"
#include "../../avrlib/rprintf.h"
#include "callbacktimerfunction.h"
#include "usb.h"
#include "usbhal.h"
#define CS_RTL8019AS (*((volatile unsigned char*)0x3000))
char G_hh[]="AVR2560 Start!\n";
void XBUS_initialize(void) __attribute__ ((naked)) __attribute__ ((section(".init1")));
void XBUS_initialize(void)
{
//###
//### Memory Address规侥 Access.
//### WinAVR 荤侩矫 馆靛矫 Linker Option阑 汲沥且 巴.
//### [Linker Option 郴侩]
//### -Wl,--section-start=.data=0x808000,--defsym=__heap_end=0x80ffff
//###
MCUCR=0x00; //JTAG Diable.
XMCRA=0xC3; //Wait-state Select Bit for UpperSector(00b), Wait-state Select Bit for LowerSector(11b),
XMCRB=0x80;
}
//###
//### System 檬扁拳 Code.
//###
void SystemInit(void)
{
// Port A initialization Direction=>(1:Out, 0:In)
PORTA=0x00;
DDRA=0x00;
// Port B initialization
PORTB=0x00;
DDRB=0x00;
// Port C initialization
PORTC=0x00;
DDRC=0x00;
// Port D initialization
PORTD=0x00;
DDRD=0x00;
// Port E initialization
PORTE=0x00;
DDRE=0x00;
// Port F initialization
PORTF=0x00;
DDRF=0x00;
// Port G initialization
PORTG=0x00;
DDRG=0x00;
// Port H initialization
PORTH=0x00;
DDRH=0x00;
// Port J initialization
PORTJ=0x00;
DDRJ=0x00;
// Port K initialization
PORTK=0x00;
DDRK=0x00;
/*
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer 3 Stopped
// Mode: Normal top=FFFFh
// Noise Canceler: Off
// Input Capture on Falling Edge
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Timer 3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;
*/
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK0=0x00;
TIMSK1=0x00;
TIMSK2=0x00;
TIMSK3=0x00;
TIMSK4=0x00;
TIMSK5=0x00;
EIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
//SFIOR=0x00;
//###
//### 扁鸥 Register 檬扁拳.
//###
PORTE|=0xC0;
DDRE=0xC2; //1100 0010
//|||| ||||
//|||| |||+-- RXD0
//|||| ||+--- TXD0
//|||| |+---- PE2
//|||| +----- PE3
//|||+------- USB_INT
//||+-------- RTL_INT
//|+--------- SD_nCS
//+---------- USB_RST
}
//###
//### Interrupt Handler 沥狼.
//###
void Uart0INT(unsigned char c)
{
uart0SendByte(c);
switch(c)
{
case 'a': DeleteCallBackFunc(12); break;
case 'b': PauseCallBackFunc(10); break;
case 'c': RunCallBackFunc(10); break;
}
}
//###
//### Main Code 沥狼.
//###
int main(void)
{
SystemInit();
InitCallBack(1);
uartOpen(__UART0,115200,__8BYTE,__NONE,__1STOP);
uartSetRxHandler(__UART0,Uart0INT);
rprintfInit(uart0SendByte);
rprintfStr(G_hh);
while(1)
{
USB_MgnRoutine();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -