標(biāo)題: 麻煩大神幫我看看為什么繼電器無法吸合?附單片機(jī)程序 [打印本頁(yè)]

作者: W3s2c8    時(shí)間: 2022-4-17 16:08
標(biāo)題: 麻煩大神幫我看看為什么繼電器無法吸合?附單片機(jī)程序
#include <STC15F2K60S2.H>
#define u8 unsigned char
#define u16 unsigned int
   
typedef struct
{
    unsigned char b1:1;
    unsigned char b2:1;
    unsigned char b3:1;
    unsigned char b4:1;
    unsigned char b5:1;
    unsigned char b6:1;
    unsigned char b7:1;
    unsigned char b8:1;
}bits;

typedef union
{
    unsigned char hex;
    bits b;
}Hextobin;

Hextobin led_ctrl,buzzer_ctrl;
u16 count;
        
void Device_ctrl(u8 p2data,u8 p0data)
{
    P0=p0data;
    P2=p2data;
    P2=0;
}

void Timer2Init(void)        //1??@11.0592MHz
{
    AUXR &= 0xFB;        //?????12T??
    T2L = 0x66;        //??????
    T2H = 0xFC;        //??????
    AUXR |= 0x10;        //???2????
    IE2 |= 0x04;                    //????2??
  EA = 1;
}

void start(void)
{
    Device_ctrl(0xa0,0);
    led_ctrl.hex=0xff;
    Device_ctrl(0x80,led_ctrl.hex);
}

u8 step;

void led_process()
{
        if(count>=500)
    {
        count=0;
    led_ctrl.b.b1=~led_ctrl.b.b1;
    Device_ctrl(0x80,led_ctrl.hex);
        
        step++;
    }
}

void led_process2()
{
    if(step==10)
    {
        buzzer_ctrl.b.b4=1;
        Device_ctrl(0xa0,buzzer_ctrl.hex);
    }
    if(step==20)
    {
        step=0;
            buzzer_ctrl.b.b4=0;
        Device_ctrl(0xa0,buzzer_ctrl.hex);
    }
}

    void main(void)
{
    start();
    Timer2Init();
    while(1)
    {
    }
}
void t2int() interrupt 12           //????
{
    count++;
    led_process();
    led_process2();
}



作者: 51FAN2020    時(shí)間: 2022-4-17 20:12
void Device_ctrl(u8 p2data,u8 p0data)
{
    P0=p0data;
    P2=p2data;
    P2=0;
}
這里去掉P2=0;試試
作者: yzwzfyz    時(shí)間: 2022-4-18 17:02
硬件圖呢?
作者: W3s2c8    時(shí)間: 2022-4-18 19:32
51FAN2020 發(fā)表于 2022-4-17 20:12
void Device_ctrl(u8 p2data,u8 p0data)
{
    P0=p0data;

51單片機(jī)P2口不是控制鎖存器的么,如果不設(shè)置關(guān)閉鎖存器不會(huì)有影響么
作者: jshine    時(shí)間: 2022-4-19 11:29
繼電器無法吸合一般是供電不足引起,也可能輸入接反了
作者: laowang123222    時(shí)間: 2022-4-19 12:37
大概率是繼電器信號(hào)線接反了,還有別接在單片機(jī)的P0口,然后看看繼電器是高電平觸發(fā)還是低電平觸發(fā)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1