📄 untitled.c
字号:
void write_74hc595(unsigned char d);
unsigned char Sort_Port_Bit(uchar d0,uchar d1,uchar d2,uchar d3,
uchar d4,uchar d5,uchar d6,uchar d7);
#define PORTBIT(adr,bit) ((unsigned)(&adr)*8+(bit)) /*绝对寻址位操作指令*/
static bit RCLK_595 @ PORTBIT(PORTB,1);
static bit SER_595 @ PORTBIT(PORTB,2);
static bit SRCLK_595@ PORTBIT(PORTB,3);
static bit K4_RB4 @ PORTBIT(PORTB,4);
static bit K3_RB5 @ PORTBIT(PORTB,5);
static bit K2_RB6 @ PORTBIT(PORTB,6);
static bit K1_RB7 @ PORTBIT(PORTB,7);
static bit I37_RC0 @ PORTBIT(PORTC,0);
static bit JO1_RC1 @ PORTBIT(PORTC,1);
static bit JO2_RC2 @ PORTBIT(PORTC,2);
static bit JO3_RC3 @ PORTBIT(PORTC,3);
static bit JO4_RC4 @ PORTBIT(PORTC,4);
static bit JO5_RC5 @ PORTBIT(PORTC,5);
static bit B_RC6 @ PORTBIT(PORTC,6);
static bit SD_RA0 @ PORTBIT(PORTA,0);
static bit I32_RA1 @ PORTBIT(PORTA,1);
static bit I33_RA2 @ PORTBIT(PORTA,2);
static bit I34_RA3 @ PORTBIT(PORTA,3);
static bit I35_RA4 @ PORTBIT(PORTA,4);
static bit I36_RA5 @ PORTBIT(PORTA,5);
__CONFIG(WDTDIS & HS & PWRTDIS & BORDIS);
main()
{
TRISB=0xF1;
TRISC=0xC1;
RBPU=0;
TRISA=0xff;
ADCON1|=0X06; //I/O
CCP1INIT();
T2CON=0X04; //打开TMR2,且使其前分频为1,
time1_init();
GIE=1;
testdat=0;
while(1)
{
//============//开关采集OK
JO5_RC5=0;
JO4_RC4=0;
JO3_RC3=0;
left_door_sw=!I37_RC0; //左门开关
rain_jx_sw=!I36_RA5;
light_sw=!I35_RA4; //雨刮延时开关
JO5_RC5=1;
JO4_RC4=0;
JO3_RC3=0;
back_store_sw=!I37_RC0;
fore_fro_sw=!I36_RA5;
safe_belt_sw=!I35_RA4;
JO5_RC5=0;
JO4_RC4=1;
JO3_RC3=0;
back_door_sw=!I37_RC0;
back_fro_sw=!I36_RA5;
rain_rst_sw=!I35_RA4;
JO5_RC5=1;
JO4_RC4=1;
JO3_RC3=0;
right_door_sw=!I37_RC0;
little_light_sw=!I36_RA5;//左门闩
JO5_RC5=0;
JO4_RC4=0;
JO3_RC3=1;
back_remove_fro_sw=!I37_RC0;
left_door_state_sw=!I36_RA5;
JO5_RC5=1;
JO4_RC4=0;
JO3_RC3=1;
back_door_state_sw=!I37_RC0;//后门闩
warn_door_sw=!I36_RA5;
JO5_RC5=0;
JO4_RC4=1;
JO3_RC3=1;
rain_water_sw=!I36_RA5;
JO5_RC5=1;
JO4_RC4=1;
JO3_RC3=1;
engineer_sw=!I37_RC0;
right_door_state_sw=!I36_RA5;//右门闩
charge_sw=!I32_RA1;
on_sw=!I34_RA3; //点火开关
start_sw=I33_RA2;
sd_sw=!SD_RA0;
srs_sw=!B_RC6;
//============输出控制OK
JO1_RC1=1;
OutPut1=Sort_Port_Bit(
(uchar)store_out, //O8--led8
(uchar)unlock_out, //O6--led1
(uchar)tail_light_out, //O5--led3
(uchar)power_windows_out, //O4--led2
(uchar)lock_out, //O3--led4
(uchar)safe_belt_led, //O2--led5
(uchar)remove_fro_flag, //O1--led6
null_sw //NULL
);
OutPut2=Sort_Port_Bit(
(uchar)safe_belt_sound||chime_bell_flag, //O9--bell
(uchar)warn_on, //O13--led11
(uchar)rain_1, //O12--led10
(uchar)back_fro_out, //O11--led9
(uchar)light_key_flag, //O10--led7
(uchar)start_inhibit_relay, //O14--led12
(uchar)flash_on, //O15--led13
0//NULL
);
write_74hc595(OutPut1);
write_74hc595(OutPut2);
RCLK_595=0;
testdat<<=1;
RCLK_595=1;
void write_74hc595(unsigned char d)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
SRCLK_595=0;
b=0;
if(d&0x80)
b=1;
SER_595=b;
d<<=1;
SRCLK_595=1;
}
}
unsigned char Sort_Port_Bit(uchar d0,uchar d1,uchar d2,uchar d3,
uchar d4,uchar d5,uchar d6,uchar d7)
{
unsigned char PortBuffer;
PortBuffer=(PortBuffer&0x7f)|(d7<<7);
PortBuffer=(PortBuffer&0xbf)|(d6<<6);
PortBuffer=(PortBuffer&0xdf)|(d5<<5);
PortBuffer=(PortBuffer&0xef)|(d4<<4);
PortBuffer=(PortBuffer&0xf7)|(d3<<3);
PortBuffer=(PortBuffer&0xfb)|(d2<<2);
PortBuffer=(PortBuffer&0xfd)|(d1<<1);
PortBuffer=(PortBuffer&0xfe)|d0;
return(PortBuffer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -