#include <ioCC2530.h> #include <string.h> #include <stdio.h> #include "OLED.h" void init_sensor_io(void) { //1.设置IO为普通IO P0SEL |= 0xC0; P1SEL |= 0x07; //2.设置编码口为输入 P0DIR &= ~0xC0; P1DIR &= ~0x07; } uchar get_sensor_id(void) { volatile uchar temp = P0_6<<4|P0_7<<3|P1_0<<2|P1_1<<1|P1_2; return temp; } void main(void) { uchar buf[16]; port_init(); initial_lcd(); init_sensor_io(); clear_screen(); disp_string_8x16_16x16(1,1,"武汉唯众智创科技"); while(1){ //循环检测SID,一旦SID发生变化也能检测到 sprintf(buf,"Sid: %d",get_sensor_id()); disp_string_8x16_16x16(3,1,buf); Delay_ms(1000); //延时1S } } |
注:IIC的驱动程序在单独的“OLED.c”文件里面,请读者自己查看源代码 |