📄 main._c
字号:
#include <iom48v.h>
#include <macros.h>
#include "CommonDefs.h"
#include "lcd.h"
#include "iic_slave.h"
void port_init(void)
{
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0xFF;
PORTD = 0x99;
DDRD = 0xFF;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK0 = 0x00; //timer 0 interrupt sources
TIMSK1 = 0x00; //timer 1 interrupt sources
TIMSK2 = 0x00; //timer 2 interrupt sources
PCMSK0 = 0x00; //pin change mask 0
PCMSK1 = 0x00; //pin change mask 1
PCMSK2 = 0x00; //pin change mask 2
PCICR = 0x00; //pin change enable
PRR = 0x00; //power controller
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main()
{
unsigned char i = 0;
unsigned char j = 0;
unsigned char msg[] = "HITSOC Center";
unsigned char ret = 0;
unsigned char errcnt = 0;
unsigned char passcnt = 0;
unsigned char cmd = 0;
init_devices();
// LCD settings
LCD_hard_init();
LCD_cls();
LCD_puts(0,0,msg,1);
ret = i2c_slave_init_recv();
if (ret!=1) LCD_putchardec(0,1,ret,0);
else LCD_puts(0,1,"IIC recv Init",1);
while(1){
delay_nms(100);
// keyboard input
DDRC &= 0xF0;
PORTC |= 0x0F;
_NOP();
i = PINC & 0x0F;
// LCD display
// LCD_putchar(10*8,1,'0'+i,0);
// IIC Transmission
if (i == 0x07){
ret = i2c_slave_recvcommand(&cmd);
if (ret != 1) LCD_putchardec(0,2,ret,0);
else LCD_puts(0,2,"recv OK.",1);
ret = i2c_slave_init_send();
if (ret!=1) LCD_putchardec(0,3,ret,0);
else LCD_puts(0,3,"IIC send Init",1);
if(cmd = 0x34){
ret = i2c_slave_sendbyte(0x89);
if (ret != 1){
LCD_puts(0,3,"transmit error.",1);
LCD_putchardec(0,4,ret,0);
LCD_putchardec(0,5,++errcnt,0);
}
else{
LCD_putchardec(0,6,++passcnt,0);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -