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

📄 main.c

📁 avr32 驱动320X64 LCD 屏代码。 对液晶驱动或学习avr的朋友有帮助。
💻 C
字号:
//ICC-AVR application builder : 2006-12-29 13:02:24
// Target : M32
// Crystal: 7.3728Mhz

#include "define.h"

extern void Init_Lcd(void) ;

void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0xFF;
 PORTB = 0x07;
 DDRB  = 0xF8;
 PORTC = 0xFF; 
 DDRC  = 0x00;
 PORTD = 0x7F;
 DDRD  = 0x80;
}

//Watchdog initialisation
// prescale: 2048K cycles
void watchdog_init(void)
{
 WDR(); //this prevents a timout on enabling
 WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
}

//TIMER0 initialisation - prescale:1024
// WGM: Normal
// desired value: 100Hz
// actual value: 101.408Hz (1.4%)
void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 TCNT0 = 0xB9; //set count
 OCR0  = 0x47;  //set compare
 TCCR0 = 0x05; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:12
void timer0_ovf_isr(void)
{
 TCNT0 = 0xB9; //reload counter value
}

//UART0 initialisation
// desired baud rate: 38400
// actual: baud rate:38400 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = 0x06;
 UBRRL = 0x0B; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0xB0;
}

#pragma interrupt_handler uart0_rx_isr:14
void uart0_rx_isr(void)
{
 //uart has received a character in UDR
}
#pragma interrupt_handler uart0_udre_isr:15
void uart0_udre_isr(void)
{
 //character transferred to shift register so UDR is now empty
}

#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
 //external interupt on INT1
}

//call this routine to initialise all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 watchdog_init();
 timer0_init();
 uart0_init();

 MCUCR = 0x08;
 GICR  = 0x80;
 TIMSK = 0x01; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}

void main(void)
{
 init_devices();
 Init_Lcd();
}

⌨️ 快捷键说明

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