electromagneticDev组件



#ifndef _ELECTROMAGNETIC_DEV_H
#define _ELECTROMAGNETIC_DEV_H

extern uint8_t elecMagState;

void relay_on();
void relay_off();
void buzzer_toggle();

#endif



#include <stc15f2k60s2.h>
#include "stdint.h"
#include "electromagneticDev.h"

uint8_t elecMagState = 0x00;

void relay_on() {
	elecMagState |= 0x10;
	
	P2 = (P2 & 0x1F) | 0xA0;
	P0 = elecMagState;
	P2 &= 0x1F;
}

void relay_off() {
	elecMagState &= 0xEF;	//~0x10
	
	P2 = (P2 & 0x1F) | 0xA0;
	P0 = elecMagState;
	P2 &= 0x1F;
}

void buzzer_toggle() {
	elecMagState ^= 0x40;
	
	P2 = (P2 & 0x1F) | 0xA0;
	P0 = elecMagState;
	P2 &= 0x1F;
}


你可能感兴趣的:(electromagneticDev组件)