Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic 12f629 software issue

Status
Not open for further replies.

gutisie

Junior Member level 1
Joined
Apr 26, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,426
Hi there!!, i have a problem with my code.
I am using pic 12f629, and mplab universal suite compiler.

I would kindly request that someone check why my code is not counting the switch pulses.

The code is design for starting with the led on, and if the buton is pressed 3 times, then switch off the led for say 1 s, and start again.

Hence, please find below what i think it should be. But no luck so far...

Code:
#include <htc.h>
#define _XTAL_FREQ 4000000
#define MAXBBS 
#define IRLED GPIO2
#define MOTOR GPIO1
#define SENSOR GPIO3
#define DelayS(T) {unsigned char i; for(i=0; i<T*10; i++) __delay_ms(100);}

__CONFIG(MCLRDIS & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);


void main()
{
	unsigned char cnt1ms;

	TRISIO = 0b111001;
	OPTION = 0b11010100;
	
	for (;;){
		IRLED = 1;
		MOTOR = 1;
		
	cnt1ms = 0;
	while (SENSOR==1 && cnt1ms<1000/1){
		TMR0 = 0;
		while(TMR0<1000/32)
			;
		++cnt1ms;
	}
	if(cnt1ms=MAXBBS/1)
		MOTOR = 0;
	DelayS(1);
	}
}

here the changes would be sensor=switch, and motor=led

thanks.
 

why my code is not counting the switch pulses.

simple: you didn't design it to do what you want.

let me write it out, in plain english:

Code:
turn on irled and motor;
reset switch pulse counter;
start cycle:
  if switch pressed, increment pulse counter;
  if pulse counter = 3 {
    reset switch pulse counter;
    turn off the led;
    delay for 1 second;
    turn on the led;
  }
  return to start of the cycle.
it is so simple that even a caveman can do it.
 
Last edited:

simple: you didn't design it to do what you want.

let me write it out, in plain english:

Code:
turn on irled and motor;
reset switch pulse counter;
start cycle:
  if switch pressed, increment pulse counter;
  if pulse counter = 3 {
    reset switch pulse counter;
    turn off the led;
    delay for 1 second;
    turn on the led;
  }
  return to start of the cycle.
it is so simple that even a caveman can do it.

Thanks so much, it is good to have in this forums cavemen ready to help us.
:lol:
Regards.
 

yeah, except that it speaks volume about you when you cannot do what a caveman can.
 

are you speaking or are you farting? :-D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top