2676 views|12 replies

142

Posts

0

Resources
The OP
 

I don't understand why the if statement [Copy link]

 

This post is from PCB Design

Latest reply

This is the problem he described  Details Published on 2018-1-2 08:46
 

142

Posts

0

Resources
2
 
Why does 16 become 15?
This post is from PCB Design

Comments

Array subscripts start at 0, so they only go up to 15, for a total of 16 elements. I also wish you a happy holiday and progress in your studies.  Details Published on 2018-1-2 08:32
Array subscripts start at 0, so they only go up to 15, for a total of 16 elements. I also wish you a happy holiday and progress in your studies.  Details Published on 2017-12-29 13:04
 
 

113

Posts

0

Resources
3
 
Paste the entire code... I can't see the P0 value in the first section of the code, but I can see the changing position of sec.

This post is from PCB Design
 
 
 

142

Posts

0

Resources
4
 
#include

sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; //Use array to store the truth table of digital tube. Array will be introduced in detail in the next chapter unsigned char code LedChar[] = { 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E }; void main(){ unsigned char cnt = 0; //Record the number of interrupts of T0 unsigned char sec = 0; //Record the number of seconds ENLED = 0; //Enable U3 and select digital tube DS1 ADDR3 = 1; ADDR2 = 0; ADDR1 = 0; ADDR0 = 0; TMOD = 0x01; //Set T0 to mode 1 TH0 = 0xB8; //Assign initial value 0xB800 to T0 TL0 = 0x00; TR0 = 1; //Start T0 while (1){ if (TF0 == 1){ //Judge whether T0 overflows TF0 = 0; //After T0 overflows, clear the interrupt flag TH0 = 0xB8; //And re-assign initial value TL0 = 0x00; cnt++; //Count value increments by 1 if (cnt >= 50){ //Judge whether T0 overflows 50 times cnt = 0; //After reaching 50 times, the count value is cleared P0 = LedChar[sec]; //The value in the truth table corresponding to the current seconds is sent to P0 port sec++; //Seconds record increments by 1 if (sec >= 16){ //When the number of seconds exceeds 0x0F(15), restart from 0 sec = 0; } } } } }
This post is from PCB Design
 
 
 

2002

Posts

24

Resources
5
 
Array subscripts start at 0, so only up to 15, a total of 16 elements. I also wish the host a happy holiday and progress in learning
This post is from PCB Design

Comments

[attachimg]337578[/attachimg][attachimg]337579[/attachimg]  Details Published on 2018-1-2 08:14
[attachimg]337578[/attachimg][attachimg]337579[/attachimg]  Details Published on 2018-1-2 08:13
 
 
 

3471

Posts

11

Resources
6
 
In the pcb section, I posted a thread about programming. The thread was a request for help, but it didn't seem to be a request for help.
This post is from PCB Design

Comments

I will pay attention next time. I don't understand the program and want to ask why  Details Published on 2018-1-2 08:16
 
 
 

8

Posts

0

Resources
7
 
In actual use, it can be written as if(++sec>15) { sec=0; } which is shorter
This post is from PCB Design

Comments

I don't understand why these two are different, sec>=16 becomes sec>=15  Details Published on 2018-1-2 08:18
 
 
 

142

Posts

0

Resources
8
 
shower.xu posted on 2017-12-29 13:04 Array subscripts start at 0, so they only go up to 15, a total of 16 elements. I also wish the host a happy holiday and progress in learning


This post is from PCB Design
 
 
 

142

Posts

0

Resources
9
 
shower.xu posted on 2017-12-29 13:04 Array subscripts start at 0, so they only go up to 15, for a total of 16 elements. I also wish the host a happy holiday and good learning
I want to ask why these two are the same
This post is from PCB Design
 
 
 

142

Posts

0

Resources
10
 
ienglgge posted on 2017-12-29 13:49 In the pcb section, I posted a thread about programming. The post was a help post. It didn't seem to be a help post. .
I will pay attention next time. I don't understand the program I want to ask why
This post is from PCB Design
 
 
 

142

Posts

0

Resources
11
 
treesss posted on 2017-12-30 18:17 In actual use, it can be written as if(++sec>15) { sec=0; } which is shorter
I don't understand why these two are different, sec>=16 becomes sec>=15
This post is from PCB Design

Comments

This is the problem he describes.  Details Published on 2018-1-2 08:46
 
 
 

1972

Posts

0

Resources
12
 
There is something wrong with this description
This post is from PCB Design
 
 
 

506

Posts

0

Resources
13
 
dinghao1 posted on 2018-1-2 08:18 I don't understand why these two are different, sec>=16 becomes sec>=15
This is the problem he described
This post is from PCB Design
 
 
 

Guess Your Favourite
Just looking around
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