Project with "IF" function and timer

I've already given you code and you didn't understand that.

--

Rick
Reply to
rickman
Loading thread data ...

After some headaches, I finally found the solution.

#include

#define LED BIT6 #define BUTTON BIT3

void main(void) { WDTCTL = WDTPW|WDTHOLD; P1DIR = LED; P1REN = BUTTON; P1OUT = BUTTON;

while(1){ if((P1IN & BUTTON) == 0x00){ __delay_cycles(5000); if((P1IN & BUTTON) == 0x00){ P1OUT ^= LED; while((P1IN & BUTTON) == 0x00); }}} }

Now, I just have to adapt it with the timer with the LED (GREEN if < 1sec; RED if > 2sec)

--------------------------------------- Posted through

formatting link

Reply to
Iron-Sim

Can you explain exactly what the above code is doing? Add some comments to explain what the various lines are doing and why.

How long is your delay in ms?

--

Rick
Reply to
rickman

Hello,

I am back ad after some study, I found this code for my program.

To answer to you Rick, the delay is 5ms for the deboune and at each push on the button, the bit are 0 (no light) or 6 (light).

Can someone check and tell me where I am wrong because I am quite lost.

Thanks a lot.

#include

#define GREEN_LED 0x40 // Définit le terme "GREEN_LED" comme étant la sortie P1.6

#define RED_LED 0x01 // Définit le terme "RED_LED" comme étant la sortie P1.0

#define LEDS 0x41 // Définit le terme "LEDS" comme étant la sortie P1.0 et P1.6.

#define LEDS_ETEINT 0x00 // Définit le terme "LEDS_ETEINT" comme étant aucune sortie donc LEDs fermées.

#define BUTTON BIT3 // Définit le terme" BUTTON" comme étant l'entrée P1.3

long tps; //Définit ma variable du temps

void main(void) //Fonction principale lancée au reset

{ WDTCTL = WDTPW + WDTHOLD; // Arrête timer du Watchdog P1DIR = LEDS; //Configure le port P1.0 et P1.6 en sortie P1OUT = LEDS_ETEINT; //LEDs éteinte au démarrage

BCSCTL2 = SELS; // SMCLK = LFXT1CLK (quartz) TA0CTL = MC_1 + TASSEL_2 + TACLR + ID_2; // On sélectionne le mode montée / La sub-main clock / TAR Clear / On divise l'horloge par 4

while (1) //Boucle infinie { while ((P1IN & BUTTON) == 1) // Tant que le bouton est enfoncé {} //? rien ne se passe if ((P1IN & BUTTON) == 0) // Tant que le bouton n'est pas enfoncé {__delay_cycles(5000);} // Délai anti-rebonds while ((P1IN & BUTTON) == 1) // Tant que le bouton est enfoncé {} while ((P1IN & BUTTON) == 0) // Tant que le bouton est enfoncé { if ((P1OUT == GREEN_LED)||(P1OUT == RED_LED)) // Si l'une des LEDs est allumé

{ P1OUT = LEDS_ETEINT; // ... On les éteint } else //Sinon {tps++; //... on met en route le compteur if(tps 2 sec P1OUT = RED_LED ;//... On allume la LED rouge } } } } }

--------------------------------------- Posted through

formatting link

Reply to
Iron-Sim

What part of this code are you having trouble with? Can you translate the comments for me?

--

Rick
Reply to
rickman

WHY THE HELL ARE YOU DELAYING 3seconds IN AN INTERRUPT HANDLER?

AND IF __delay_cycles(100000); IS 3seconds, then

this is 10000 times longer!!!!!!!!!!!!!!!!!!!!!

My advice is to STAY AWAY from using interrupt handlers until you understand what they really are. rickman's suggestion is one you should follow.

ed

Reply to
Ed Prochak

I don't think he is trying to learn really. I expect this is an assignment and he is trying to get something to work as quickly as possible. It's not a difficult assignment really, but he needs to

*learn* about the issues involved rather than just copying code from the Internet.
--

Rick
Reply to
rickman

On Sunday, June 14, 2015 at 5:50:34 PM UTC-4, rickman wrote: []

yes, he seems to be doing on the job learning, poorly. That seems to be the modern mentality: "I don't need to understand how it works. I'll just throw code at it until something happens."

I hope he follows your advice. ed

Reply to
Ed Prochak

I remember being in a hurry myself when I was in school. I thought I was learning everything I needed and the actual practice of the craft was just an "exercise". lol. I'm still learning the practice of the craft.

--

Rick
Reply to
rickman

Thirty plus years doing software and I'm still learning. 8^)

Hey Iron Slim,

is this helping? ed

Reply to
Ed Prochak

Yes, there are still a few of us old timers out here who not only programmed "right down on the iron" in assembly language, we may have set bootstrap loaders with toggle switches(!!!) and even did a little programming in straight octal/hexadecimal, not even assembly language. It seems that these days to too many young whippersnappers, CPUs are just black boxes about which they have little understanding how they really work under the covers. I wonder even about embedded systems in which people code in C? Do they really understand what is going on in the hardware layer? Do they need to?

--
Paul Bartlett
Reply to
Paul Bartlett

Some architectures like PDP-11 and 8080 are naturally octal (three bit groups) while others, such as IBM360/370 as well as VAX-11 series are essentially hexadecimal (4 bit groups).

Doing front panel programming with toggle switches was not a big deal. On some architectures calculating the branch relative offset required pen and paper, otherwise programming with toggle switches or 8/16 position rotary swathes was quite easy.

I still do not understand why intel swathes from octal ( 2 bit opcode and 3 bit destination address and 3 bit source address) to hexadecimal on 8080 and 8085.

Reply to
upsidedown

IIRC, Heathkit's assembler used octal instead of hex by default for

8080/8085/Z80. Probably due to the previous work with PDP-11 kits.
--
Grant Edwards               grant.b.edwards        Yow! And then we could sit 
                                  at               on the hoods of cars at 
                              gmail.com            stop lights!
Reply to
Grant Edwards

(snip)

The Altair 8800 front panel has the LEDs grouped in threes.

More than one I have known has sticky labels to divide them into groups of four, instead. Even if it is more natural as octal, if you are more used to hex, it is easier that way.

Also, the PDP-11 with 16 its, and the 8080 with eight, don't map to whole numbers of octal digits. That complicates working with them in octal.

-- glen

-- glen

Reply to
glen herrmannsfeldt

How about microcode? Anyone else done that?

--

Rick
Reply to
rickman

It does? I have seen many a listing in octal and it works wonderfully with the LSI-11. Who cares about the left digit being just one bit?

--

Rick
Reply to
rickman

Not that I recall.

I remember seeing Z80 listings that used split octal notation for addresses and other 16-bit values: 000_000 to 377_377. I thought that a bit odd, but never worked with that notation enough to comment on it's utility.

--
Grant Edwards               grant.b.edwards        Yow! I left my WALLET in 
                                  at               the BATHROOM!! 
                              gmail.com
Reply to
Grant Edwards

If you've never used a flat bladed screw driver I expect you wouldn't be very good with that either.

--

Rick
Reply to
rickman

If you just enter a program from a listing (generated by assembler or manually assembled) with toggle switches, it is quite irrelevant if octal or hex is used. Of course, if you have a hex keypad, using hex will save a lot of keystrokes.

My original point was about writing a program into memory through front panel toggle switches without any paper listing. In this case it is essential that the mode (octal/hex) matches the machine architecture. Using hex on a PDP-11/8080/Z80 requires remember the whole 8 or 16 bit opcode. For PDP-11 dual operand instructions, you only needed to remember a 3 bit opcode, then use the byte/word bit (most significant bit) the addressing mode (3 bits), (base)register (3 bits) for the first operand and 3+3 bits for the other operand.

Reply to
upsidedown

Sometimes also called key-in loader -)

Reply to
upsidedown

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.