📄 main.c
字号:
#include "all_inc.h"
void port_init(void)
{
// 输入/输出口初始化 DDRxn-方向配置 (1-输出 0-输入) PORTxn-上拉电阻配置 (1-上拉使能)
// Port A
// 7 6 5 4 3 2 1 0
//PORTA7 PORTA6 PORTA5 PORTA4 PORTA3 PORTA2 PORTA1 PORTA0
PORTA = 0xff;
DDRA = 0xff;
// Port B
// 7 6 5 4 3 2 1 0
//PORTB7 PORTB6 PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0
// MISO MOSI SCK S\S
PORTB = 0xff;
DDRB = 0x97;
// Port C
// 7 6 5 4 3 2 1 0
//PORTC7 PORTC6 PORTC5 PORTC4 PORTC3 PORTC2 PORTC1 PORTC0
PORTC = 0x7;
DDRC = 0xf7;
// Port D
// 7 6 5 4 3 2 1 0
//PORTD7 PORTD6 PORTD5 PORTD4 PORTD3 PORTD2 PORTD1 PORTD0
PORTD = 0x0;
DDRD = 0xff;
// Port E
// 7 6 5 4 3 2 1 0
//PORTE7 PORTE6 PORTE5 PORTE4 PORTE3 PORTE2 PORTE1 PORTE0
PORTE = 0xff;
DDRE = 0xff;
// Port F
// 7 6 5 4 3 2 1 0
//PORTF7 PORTF6 PORTF5 PORTF4 PORTF3 PORTF2 PORTF1 PORTF0
PORTF = 0x0;
DDRF = 0x0;
// Port G
// 7 6 5 4 3 2 1 0
// – – – PORTG4 PORTG3 PORTG2 PORTG1 PORTG0
PORTG = 0x1b;
DDRG = 0x1b;
/*
// Port H
DDRH = 0x00;
PORTH = 0xff;
// Port I
DDRI = 0x00;
PORTI = 0xff;
// Port J
DDRJ = 0x00;
PORTJ = 0xff;
*/
}
//SPI initialize
// clock rate: 1382374hz @11.0592 2x
void spi_init(void)
{
SPCR = 0x51; //setup SPI
SPSR = 0x01; //setup SPI
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
__disable_interrupt(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
spi_init();
adc_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
__enable_interrupt(); //re-enable interrupts
//all peripherals are now initialized
}
//字符串拷贝
void StringCopy(char *from,unsigned char *to,unsigned char len)
{
unsigned char i;
for(i=0;i<len;i++)
{
to[i] = from[i];
}
}
void Delay_ms(unsigned int ms)
{
while(ms--)
{
__delay_cycles(3000);
}
}
/*------------------主程序--------------------*/
signed long sum=0;
void main()
{
init_devices();
while(1)
{
sum = read_adc();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -