897 views|15 replies

108

Posts

0

Resources
The OP
 

Traffic light toys, about the problem of lighting, everyone can help [Copy link]

 

It turned out that the problem with the traffic light was that sometimes it worked normally, and sometimes it didn't. I suspected it was a problem with the IC socket, so I soldered 51 directly to the board, but the problem still existed.

I made the program the simplest one, and found that the light is not normal (it is always off, always on, and sometimes it can flash). Can anyone help me take a look?

Another problem is that when I use EP51 to burn the program, only 1 out of 10 times can be burned successfully. I don’t know what’s going on.

The simplest code is as follows (I really can't think of any other problems):

#include <reg52.h>

unsigned char counter_1s;
#define LED_ON      0
#define LED_OFF     1
sbit led_run = P1^3;


void delay(int ms);

void initT0()
{
    TMOD = 0x01;
    TH0 = 0xD8;
    TL0 = 0xF0;
    
    EA = 1; // Enable Switch 
    ET0 = 1; // T0 inter
    TR0 = 1;
}

void main( void )   
{
    initT0();
    P0 = 0;
    P1 = 0;
    P2 = 0;
    counter_1s = 0;
    delay(1000);

    while(1)
    {
    }
}   

void delay(int ms)
{
  int i,j;
  for(i = 0; i<ms; ++i)
    for(j = 0; j<110; ++j);
}

void interrupt_t0() interrupt 1
{
    // 10ms
    TH0 = 0xD8;
    TL0 = 0xF0;
  
    counter_1s++;
    if(counter_1s == 100)
    {
        counter_1s = 0;
        led_run = ~led_run;
    }
}

This post is from 51mcu

Latest reply

It is recommended to find a good program on the Internet to check whether it is a hardware problem or a program problem?   Details Published on 2023-12-19 19:00
 

2w

Posts

0

Resources
2
 

Is the quartz crystal oscillating normally?

Is the RST pin floating, is the reset correct?

Does the program execute normally from the beginning?

This post is from 51mcu

Comments

The crystal oscillator started to vibrate. The oscilloscope measured that RST was not used, so it should be executed if it is omitted. Otherwise, it would not work sometimes.  Details Published on 2023-12-13 08:26
 
 
 

108

Posts

0

Resources
3
 
maychang posted on 2023-12-12 19:46 Did the quartz crystal start to oscillate normally? Is the RST pin floating, is the reset correct? Does the program execute normally from the beginning?

The crystal oscillator started to vibrate, and the oscilloscope measured

RST is not used, so it is omitted

It should be executed, otherwise it won't work sometimes.

This post is from 51mcu

Comments

[RST is not used, so it is omitted] For 51 MCU, the reset circuit cannot be omitted. If RST is left floating, the MCU may not be able to start executing the program at all. As for [sometimes it works], it is not worth learning. [Sometimes it works], of course the program is executed, but [sometimes it runs away], obviously it is not executed normally.  Details Published on 2023-12-13 08:56
 
 
 

2w

Posts

0

Resources
4
 
Yunhu Congbai published on 2023-12-13 08:26 The crystal oscillator started to vibrate, and the oscilloscope measured that RST was not used, so it should be executed if it is omitted, otherwise it would not work sometimes

[RST is not used, so it is omitted]

For 51 MCU, reset circuit is usually not omitted. If RST is left floating, the MCU may not be able to start executing the program at all. As for [sometimes it works], it is not worth learning. [Sometimes it works], of course the program is executed, but [sometimes it runs away], obviously it is not executed normally.

This post is from 51mcu
 
 
 

1w

Posts

142

Resources
5
 

Complete the circuit.

This post is from 51mcu

Comments

[attachimg]764391[/attachimg] There is a flying wire on the reset circuit board   Details Published on 2023-12-16 14:47
 
Personal signature上传了一些书籍资料,也许有你想要的:https://download.eeworld.com.cn/user/chunyang
 
 

108

Posts

0

Resources
6
 

This post is from 51mcu
 
 
 

73

Posts

0

Resources
7
 

Is the quartz crystal oscillating normally?

Is the RST pin floating, is the reset correct?

Is the program running normally from the beginning?

51 MCU, reset circuit is generally not omitted. If RST is left floating, the MCU may not be able to start executing the program at all. As for [sometimes it works], it is not worth learning. [Sometimes it works], of course the program is executed, but [sometimes it runs away], obviously it is not executed normally.

Women's study, summary

This post is from 51mcu

Comments

Is the program running normally from the beginning? --- How to confirm this? Now it has been simplified to the logic of turning on a light. The big guys in the group said that the light is driven directly by the IO port, and the LED is more suitable for grounding.  Details Published on 2023-12-16 11:39
Is the program running normally from the beginning? --- How to confirm this? Now it has been simplified to the logic of turning on a light. The big guys in the group said that the light is driven directly by the IO port, and the LED is more suitable for grounding.  Details Published on 2023-12-16 11:38
 
 
 

108

Posts

0

Resources
8
 
haocede posted on 2023-12-16 11:02 Is the quartz crystal oscillating normally? Is the RST pin floating, is the reset correct? Is the program running normally from the beginning? 51 single-chip microcomputer, reset circuit...

Is the program running normally from the beginning?

---How to confirm this? Now it has been simplified to the logic of turning on a light.

The big guys in the group said that it is more appropriate to use the IO port to directly drive the light, and the LED is more suitable to be grounded

This post is from 51mcu

Comments

Apparently the "big brother in the group" is too inexperienced. You should try to use negative logic drive, that is, it is better to connect the LED as shown in your diagram, because the current sinking capability of the MCU you use is stronger than the current sourcing capability.  Details Published on 2023-12-19 14:25
 
 
 

108

Posts

0

Resources
9
 
haocede posted on 2023-12-16 11:02 Is the quartz crystal oscillating normally? Is the RST pin floating, is the reset correct? Is the program running normally from the beginning? 51 single-chip microcomputer, reset circuit...

The oscillation is normal, I manually fly the RST line

This post is from 51mcu
 
 
 

108

Posts

0

Resources
10
 
chunyang posted on 2023-12-14 00:11 Give the circuit complete.
There is a flying wire on the reset circuit board

This post is from 51mcu

Comments

Write a simple program first, and don't worry about anything else. Just drive the LED on the P1.3 pin to make it flash, and then make it flash a specific number of times. First verify the basic hardware platform, then master the simplest programming and burning operations, step by step.  Details Published on 2023-12-19 14:22
 
 
 

1w

Posts

142

Resources
11
 
Yunhu Congbai published on 2023-12-16 14:47 There is a flying wire on the reset circuit board

Write a simple program first, and don't worry about anything else. Just drive the LED on the P1.3 pin to make it flash, and then make it flash a specific number of times. First verify the basic hardware platform, then master the simplest programming and burning operations, step by step.

This post is from 51mcu
 
Personal signature上传了一些书籍资料,也许有你想要的:https://download.eeworld.com.cn/user/chunyang
 
 

1w

Posts

142

Resources
12
 
Yunhu Congbai posted on 2023-12-16 11:38 Whether the program is executed normally from the beginning --- how to confirm this, now it has been simplified to the logic of turning on a light. The big...

Apparently the "big brother in the group" is too inexperienced. You should try to use negative logic drive, that is, it is better to connect the LED as shown in your diagram, because the current sinking capability of the MCU you use is stronger than the current sourcing capability.

This post is from 51mcu

Comments

Self-confidence collapsed and the light failed to light up. . . #include unsigned char counter_1s; #define LED_ON 0 #define LED_OFF 1 sbit led_run = P1^3; void delay(int ms);  Details Published on 2023-12-19 17:49
 
Personal signature上传了一些书籍资料,也许有你想要的:https://download.eeworld.com.cn/user/chunyang
 
 

108

Posts

0

Resources
13
 
chunyang posted on 2023-12-19 14:25 It is obvious that the "big brother in the group" is too inexperienced. Negative logic drive should be used as much as possible, that is, the LED is connected as shown in your diagram, because the MCU you use is charged...

Self-confidence collapsed and the lamp failed to light. . .

#include <reg52.h>

unsigned char counter_1s;
#define LED_ON      0
#define LED_OFF     1
sbit led_run = P1^3;


void delay(int ms);

void initT0()
{
    TMOD = 0x01;
    //TH0 = 0xD8;
    //TL0 = 0xF0;
    TH0 = 0xDC;
    TL0 = 0x00;
    
    EA = 1; // Enable Switch 
    ET0 = 1; // T0 inter
    TR0 = 1;
}

void main( void )   
{
    initT0();
    counter_1s = 0;

    while(1)
    {
    }
}   

void delay(int ms)
{
  int i,j;
  for(i = 0; i<ms; ++i)
    for(j = 0; j<110; ++j);
}

void interrupt_t0() interrupt 1
{
    // 10ms
    //TH0 = 0xD8;
    //TL0 = 0xF0;
    TH0 = 0xDC;
    TL0 = 0x00;
  
    counter_1s++;
    if(counter_1s == 100)
    {
        counter_1s = 0;
        led_run = ~led_run;
    }
}

This post is from 51mcu
 
 
 

19

Posts

2

Resources
14
 

Is it possible that there is a problem with your circuit board soldering?

This post is from 51mcu
 
 
 

19

Posts

2

Resources
15
 

It is recommended to find a good program on the Internet to check whether it is a hardware problem or a program problem?

This post is from 51mcu
 
 
 

108

Posts

0

Resources
16
 

26074efc03bdb01bc031eb20793fafad

Give up 51 and switch to M0, which is much better.

Thank you for your support.

This post is from 51mcu
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list