这个电路是通过mega16单片机控制三极管然后驱动继电器吸合。继电器另一半控制220V电灯
仿真截图:
Atmel Studio6.2编译通过截图
原程序:
- /*
- * GccApplication16.c
- *
- * Created: 2014-10-11 19:16:38
- * Author: Administrator
- */
- #define F_CPU 0x8000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- #include <stdint.h>
- #define K1_DOWN() (PINB & _BV(PB7))
- #define RELAY_SWITCH() PORTD^= _BV(PD4)
- int main(void)
- {
- DDRD = 0xFF;
- PORTD = 0xFF;
- DDRB = 0x00;
- PORTB = 0xFF; //PB端口内部上拉
-
- while(1)
- {
- if(K1_DOWN())
- {
- while(K1_DOWN());
- RELAY_SWITCH();
- _delay_ms(20);
- }
-
-
- }
- }
|