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

📄 mainfile.c

📁 用SL811做USB主机的源码
💻 C
字号:
//ICC-AVR application builder : 2004-7-29 10:44:22
// Target : M128
// Crystal: 16.000Mhz

#include <iom128v.h>
#include <macros.h>
#include "define.h"
#include "ziku.h"
#include <stdio.h>
#include "eeprom.h"
#define EPROM_READ(addr,dst) EEPROMReadBytes(addr,&dst,sizeof(dst))
#define EPROM_WRITE(addr,src) EEPROMWriteBytes(addr,&src,sizeof(src))


#include "Mainpro.h"

#include "sl811_host.h"

//#include "TX.h"
#include "subprogram.h"


void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0xFF;
 PORTB = 0xFF;
 DDRB  = 0xFF-8;//MISO
 PORTC = 0xFF; //m103 output only
 DDRC  = 0xFF;
 PORTD = 0xFF;
 DDRD  = 0xFB;
 PORTE = 0xFF;
 DDRE  = 0xAE;
 PORTF = 0xFF-3;//A17_A16_low
 DDRF  = 0x3F;
 PORTG = 0x1F;
 DDRG  = 0x1F;
}

//TIMER0 initialisation - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value:  1.000mSec (0.0%)
void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 ASSR  = 0x00; //set async mode
 TCNT0 = 0x06; //set count
 OCR0  = 0xFA;
 TCCR0 = 0x04; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{unsigned char temp;
 SEI();
 TCNT0 = 0x06; //reload counter value
 
 temp=PORTF;//保存sram和显示ram的切换PF1
 A17_low
 	   SPI();
//	   adc_process();
	   //send_datas();
	   
	   flash400ms();
 PORTF=temp;	   
}

//TIMER3 initialisation - prescale:Stop
// WGM: 3) PWM 10bit phz correct, TOP=0x3FF
// desired value: 1Hz
// actual value: out of range
void timer3_init(void)
{ 
 TCCR3B = 0x00; //stop
 TCNT3H = 0xFC; //setup
 TCNT3L = 0x01;
 OCR3AH = 0x03;
 OCR3AL = 0xFF;
 OCR3BH = 0x03;
 OCR3BL = 0xFF;
 OCR3CH = 0x00;
 OCR3CL = 248;
 ICR3H  = 0x03;
 ICR3L  = 0xFF;
 TCCR3A = 0x0B;
 TCCR3B = 0x02; //start Timer
}

//UART0 initialisation
// desired baud rate: 57600
// actual: baud rate:58824 (2.1%)
// char size: 9 bit
// parity: Disabled
void uart0_init(void)
{
/*
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x00;
 UCSR0C = 0x06;
 UBRR0L = 0x10; //set baud rate lo		Baud-Rate=57600
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0xDC;
*/
//和计算机通信
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x00;
 UCSR0C = 0x06;
 UBRR0L = 0x67; //set baud rate lo
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0x18;
}

#pragma interrupt_handler uart0_rx_isr:19
void uart0_rx_isr(void)
{
 //uart has received a character in UDR
}

#pragma interrupt_handler uart0_tx_isr:21
void uart0_tx_isr(void)
{
 //character has been transmitted
}

//UART1 initialisation
// desired baud rate:57600
// actual baud rate:58824 (2.1%)
// char size: 9 bit
// parity: Disabled
/*
void uart1_init(void)
{
 UCSR1B = 0x00; //disable while setting baud rate
 UCSR1A = 0x00;
 UCSR1C = 0x06;
 UBRR1L = 0x10; //set baud rate lo
 UBRR1H = 0x00; //set baud rate hi
 UCSR1B = 0xDC;
}
*/
//UART1 initialisation
// desired baud rate:57600
// actual baud rate:58824 (2.1%)
// char size: 9 bit
// parity: Disabled
void uart1_init(void)
{
 UCSR1B = 0x00; //disable while setting baud rate
 UCSR1A = 0x00;
 UCSR1C = 0x06;
 UBRR1L = 0x10; //set baud rate lo
 UBRR1H = 0x00; //set baud rate hi
 UCSR1B = 0x1C;
 
}


#pragma interrupt_handler uart1_rx_isr:31
void uart1_rx_isr(void)
{
//uart has received a character in UDR
}

#pragma interrupt_handler uart1_tx_isr:33
void uart1_tx_isr(void)
{
 //character has been transmitted
}

//ADC initialisation
// Conversion time: 13uS
void adc_init(void)
{
 ADCSRA = 0x00; //disable adc
 ACSR  = 0x80;
 ADCSRA = 0x84;
}

#pragma interrupt_handler int4_isr:6
void int4_isr(void)
{//时间保护中断
  //external interupt on INT4
}



#pragma interrupt_handler int6_isr:8
void int6_isr(void)
{unsigned char temp;


 temp=PORTF;//保存sram和显示ram的切换PF1
 A17_low
 		int0_isr();
 PORTF=temp;	   

//external interupt on INT6
}


//SPI initialisation
// clock rate: 2000000hz
void spi_init(void)
{
 SPCR= 0x00; //diable spi
 SPSR= 0x00; //2X
 SPCR= 0x7c; //setup SPI
}


//call this routine to initialise all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x4E; //external memory
 MCUCR = 0xC0;
 port_init();
 uart0_init();
 uart1_init(); 
 timer0_init();
 timer3_init();
 adc_init();
 spi_init();
 twi_init();

 EICRA = 0x00; //extended ext ints	外部中断的类型控制
 EICRB = 0x00; //extended ext ints   00=low;22=falling实际中是low
 EIMSK = 0x40;//打开intr4,intr6
 TIMSK = 0x01; //timer interrupt sources
 ETIMSK = 0x00; //extended timer interrupt sources
 
 SEI(); //re-enable interrupts
 
 //all peripherals are now initialised
}


void main(void)
{ 	 init_devices();	 
	 init_ram();
 	 init_sl811_master();
	 En_485_low//禁止发送数据
	
	
 for(;;)
 {	LED();
	ram_cpl
 	clear_screen();
 	lg_main();

	display_pages();
 }
}

⌨️ 快捷键说明

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