STC15f101W做常规的逻辑控制,keil uvision3编译时出现0错误,3警告。希望哪位大侠能抽空帮忙。pcb没回来,还不知烧录结果。
/******************************************/
#include "stc15f2k.h"
#include <intrins.h>
#define MAIN_Fosc 22118400L //定义主时钟
#define uchar unsigned char
/************* 本地声明 **************/
sbit AC_Fail=P3^2;
sbit Iout_rev=P3^3;
sbit Out=P3^4;
sbit Onoff=P3^5;
bit Operated_flag;
bit Soft_shutdown_state;
bit sys_no_output;
bit Ups_operating_flag;
uchar aa=0;
void onoff_sw_ensure();
void initial();
void delay_ms(uchar bb);
void soft_shutdown_detect();
void operated_detect();
void turn_off();
void restart();
/********************** initial ************************/
void intial(){
P3M1=0; //设置P3^2,^3,^5输入
P3M0=0x10; //设置P3^4输出
Out=1;Soft_shutdown_state=0;sys_no_output=0;
Ups_operating_flag=0; Operated_flag=0;}
//**onoff ensure**//
void onoff_sw_ensure(){
if((Onoff==0)&&(Iout_rev==1)&&(Out==0))
Out=1;}
//**operated detect**//
void operated_detect(){
if((Onoff==1)&&(Iout_rev==0)&&(Operated_flag==0)){
aa++;
if(aa==100){
aa=0;
Operated_flag=1;}}}
/********************** soft_shutdown_detect************************/
void soft_shutdown_detect(){
if((Operated_flag==1)&&(Iout_rev==1)&&(Onoff==1)){
Soft_shutdown_state=1;
Operated_flag=0;}}
/********************** main ************************/
void main(){
initial();
delay_ms(1);
while(1){
onoff_sw_ensure();
operated_detect();
soft_shutdown_detect();
turn_off();
restart();}}
/********************** restart ************************/
void restart(){
if((sys_no_output==1)&&(AC_Fail==0)){
Out=1;
sys_no_output=0;
}}
/********************** turnoff ************************/
void turn_off(){
if((Soft_shutdown_state==1)&&(AC_Fail==1)&&(Onoff==1)){
Out=0; sys_no_output=1;
Soft_shutdown_state=0;};
if((Operated_flag==1)&&(AC_Fail==1)&&(Onoff==1)&&(Iout_rev==0))
{Ups_operating_flag=1;};
if((Ups_operating_flag==1)&&(Iout_rev==1)){
sys_no_output=1; Ups_operating_flag=0;Operated_flag=0;}}
/********************** delay ************************/
void delay_ms(uchar bb){
uchar cc;
for(;bb>0;bb--){for(cc=0;cc<122; cc++);}}
|