Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PORT ouputs are not wroking

Status
Not open for further replies.

srikanthind

New Member
hi, could find if there is intialisation wrong below the program, i tried to turn the GPIO4 LED on, but its not working on hardware.. its working while simulating.. am using PIC 12f675 microcontroller..
Code:
#define TRISIO_DEFAULT 0b11101101



#define GPIO_DEFAULT 0b00011001

void main(void)
{
	ANSEL = 0b00000000;
	OPTION = 0b10000001; // Configure the time (bit5=0, bit3=0, bits 2-0=100 - prescaler=32); Thus, overflow occurs each 8.192ms
	CMCON = 0b00000000;

    GPIO=0;

	GIE = 1;
	T0IE = 1;
	GPIE = 1;
	IOCB3 = 1;
	T0IF = 0;
	GPIF = 0;
   


	TRISIO = TRISIO_DEFAULT; // 
	GPIO = GPIO_DEFAULT;

	while(1){}
}



GPIO3 connected as a input, whenever it is pressed , interrrupt would occur,,
 
You really are struggling.... every post comes to the same issue.

Tell me!! What is your goal... What do you want the code to achieve and I'll help you get there..

All the code you have uploaded is in need of a good o'l sort out...
 
hi Ian, thank you very much.. am writing program for pedstrain traffic light simualtor using PIC 12f675...

. In the default state of the system, cars have open pass, whereas pedestrians have to wait. That is, make sure that the car red and amber lights are off, whereas the green light is on, and at the same time, the pedestrian red light is on and green light is off. Also, the pedestrian indicator light is off.


Upon a click on the pedestrian’s button (simulated by the button on the PIC kit breadboard), the first transition phase starts. First, the pedestrian indicator light goes on for 10 seconds and during that time any new button click would not be accepted (the five seconds are measured only from the first button click). Then, the car green light goes off and amber light on for 2s. Finally, simultaneously, the car amber light turns off, red turns on, the pedestrian red turns off, green on and indicator off.


The new state lasts for a time interval determined by the adjustable resistor on the PIC breadboard. For the minimal value, the duration should be equal to 5s, whereas for the maximal value, it should be 30s.


After expiration of the determined time interval, the second transition phase starts. First, the pedestrian green turns off, red on and this state takes 3s (safety margin time for pedestrians to move away from the road). Then, the car amber turns on simultaneously with the red light (which remains on). Finally, the car red and amber lights turn off and green turns on. The system is back to the default state and should remain in it until the next button click.

the leds are not lighting up in hardware...


just thinking did i miss or done any mistake to intialise bits



thank you




You really are struggling.... every post comes to the same issue.

Tell me!! What is your goal... What do you want the code to achieve and I'll help you get there..

All the code you have uploaded is in need of a good o'l sort out...
 
There is no point posting bits of code as the problem can be anywhere. Post your complete code and you're far more likely to get help.

Mike.
 
it might be clumsy to understand... am just beginner in PIC C

thank you for your time



Code:
/*  pin1 -- pedestrain green  (RED is NOT of GREEN)

    2--- ped LED
   
    3-- Button


    4 --- cars Green   (RED is NOT of GREEN)

    5 ---- car amber
  0 -- variable delay
*/


#define _LEGACY_HEADERS
#include <pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTDIS & INTIO);

#define TRISIO_DEFAULT 0b11101101
#define TRISIO_LED 0b11111011
#define TRISIO_LEDAMB 0B11011011
#define TRISIO_AMBER 0B111011111


#define GPIO_DEFAULT 0b00011001
#define GPIO_LED 0b00000101
#define GPIO_LEDAMB 0b00100101
#define GPIO_PED 0B000000011
#define GPIO_AMBER 0B00101001    // AMBER ON


unsigned char cnt=0, i, cnt_delay=1;

// Interrupt service routine
void interrupt Isr(void)
{
    if(GPIF)
    {
     	if(GPIO3==0)
         {
          for (cnt=0; cnt<=5; cnt++)  // prevent debouncing
           { 
            __delay_ms(1);
            if((GPIO3)==0)
            cnt=0;
           } 
         }

       
	        	 	
          for (cnt=0;cnt<73;cnt++)                    // LED ON with 10 seconds delay
         {
         TRISIO = TRISIO_DEFAULT;   // CAR GREEN LIGHT IS ON, PED RED IS OFF
         GPIO= GPIO_DEFAULT ;
         __delay_ms(150);
         TRISIO= TRISIO_LED;      // LED IS ON
         GPIO=GPIO_LED;
          }
         
// AMBER LIGHT IS ON  
      for(i=0;i<13;i++)                  // AMBER LIGHT IS ON WITH DELAY
        {
        for (cnt =0; cnt<250; cnt++); // 2 seconds delay (1.986 seconds)
         {
          TRISIO = TRISIO_LEDAMB;     // PEDSTRAIN LED INDICATOR IS ON AND AMBER IS ON
          GPIO = GPIO_LEDAMB;
          __delay_ms(150);
          TRISIO = TRISIO_DEFAULT; // CAR GREEN LIGHT IS ON, PEDSTRAIN RED IS OFF
         GPIO = GPIO_DEFAULT;
         }
        }


// task d:
     
       __delay_ms(55);

      //GPIO &= ~(1<<2);              // PED Led  indicator OFF, 
       TRISIO = TRISIO_DEFAULT;      // PED GREEN ON.
       GPIO= GPIO_PED;

       while((GPIO0 == 0) && (cnt_delay!=6))    // VARIABLE DELAY VARIES FROM 5 TO 30 SECONDS, FRACTION OF 5s
               {
                 cnt_delay++;
                 GPIO &= ~(1<<0);
                for(cnt=0; cnt<10;cnt++) // 1 second delay
                 __delay_ms(100);
                
               } 

        for(cnt_delay;cnt_delay!=0; --cnt_delay)
         {
           for(cnt=0; cnt<50;cnt++) // 5 seconds delay
            __delay_ms(100);
         }

      
        __delay_ms(155);
             
           for(i=0;i<30;i++)        // AMBER IS ON, PEDSTRAIN GREEN ON WITH 3 SECONDS DELAY
              {
                for (cnt =0; cnt<250; cnt++); // 3 seconds delay
  
                   {
                      TRISIO = TRISIO_DEFAULT;  
                      GPIO = GPIO_PED;        //PEDSTRAIN GREEN ON  
                      __delay_ms(100);
                      TRISIO= TRISIO_AMBER;  // CAR AMBER LIGHT IS ON
                      GPIO=GPIO_AMBER;
                   }
              }
         __delay_ms(155);
 
      TRISIO=TRISIO_DEFAULT;        // GOES BACK TO DEFAULT
      GPIO=GPIO_DEFAULT;
}
      GPIF=0;

 }


void main(void)
{
	ANSEL = 0b00000000;
	OPTION = 0b10000001; // Configure the time (bit5=0, bit3=0, bits 2-0=100 - prescaler=32); Thus, overflow occurs each 8.192ms
	CMCON = 0b00000000;

    GPIO=0;

	GIE = 1;
	T0IE = 1;
	GPIE = 1;
	IOCB3 = 1;
	T0IF = 0;
	GPIF = 0;
    GPIO |= (1<<3);


	TRISIO = TRISIO_DEFAULT; // 
	GPIO = GPIO_DEFAULT;

	while(1){}
}
There is no point posting bits of code as the problem can be anywhere. Post your complete code and you're far more likely to get help.

Mike.
 
Ok!! You'll need to draft a flow chart or something... You interrupt should only acknowledge / flag inputs... All the GPIO routines should be done in a shadow register and then flipped.

This will keep the interrupt at bay....

Flow chart example for a lift..

...init system
...start
...... wait for button input
...... process input, set leds
...... move lift
................wait for lift switch activation
.......stop lift and set led's
.......go to start
..end

I hope you get what I'm on about.
 
Your not going to see any thing happen till you fix this CMCON 0x00h is not going to work.
You have to turn off the comparator. With CMCON = 0x07h;
 
Status
Not open for further replies.

Latest threads

Back
Top