📄 initial.c
字号:
#include "initial.h"
#include <uart3.h>
extern void power_add_init (void);
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xC1;
DDRB = 0xFD;
PORTC = 0xA3; //m103 output only
DDRC = 0xA3;
PORTD = 0x1C;
// DDRD = 0x10;
DDRD = 0x30;
//PORTD |= 0x1C; //PD4=1
//DDRD |= 0x10; //PD4 OUTPUT 1-RX 0-TX
PORTE = 0x00;
DDRE = 0x0C;
PORTF = 0x0F;
DDRF = 0x00;
PORTG = 0x03;
DDRG = 0x03;
}
//Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x1F;
WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
}
//TIMER0 initialize - prescale:1024
// WGM: Normal
// desired value: 10mSec
// actual value: 9.984mSec (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0xB2; //set count// 计数0XFF-0XB2=0X4D= 77
// OCR0 = 0x4E;
OCR0 = 0x18;
TCCR0 = 0x07; //start timer
}
//UART1 initialize
// desired baud rate:9600
// actual baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart1_init(void)
{
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
//UBRR1L = 0x33; //set baud rate lo
//UBRR1H = 0x00; //set baud rate hi
UBRR1L = 0x0C; //
UBRR1H = 0x00; //38400
UCSR1B = 0x98;
}
//TWI initialize
// bit rate:1
void twi_init(void)
{
TWCR= 0X00; //disable twi
TWBR= 0x01; //set bit rate
TWSR= 0x01; //set prescale
//TWAR= 0x00; //set slave address
TWCR= 0x44; //enable twi
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
uart3_init();
watchdog_init();
timer0_init();
twi_init();
uart1_init();
lcd_init();
power_add_init ();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x01; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void pca9554init(void)
{
//sla_w=0x40;//uic
//command=3;
//DATA=0x08;
write_9554(0x40,3,0x08);
//pca9554writeoutreg(0x40,1,0x08);
/*sla_w=0x42;
command=1;
DATA=0x00;
pca9554writeoutreg();
sla_w=0x42;//uic1
command=3;
DATA=0x00;
pca9554writeoutreg();
sla_w=0x40;
sla_r=0x41;
command=0;
pca9554writeoutreg();
select=DATA;*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -