| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| 16F636 doubts |  
				|  Posted: Sat Apr 05, 2008 12:42 pm |   |  
				| 
 |  
				| I'm using the 16f636 but I can´t make it work perfectly well. I have four push buttons connected do ground, if I press each one the buttons I have zero in the micro (checked by the multimeter).
 So in my code I just need to test if it is a zero, right?
 So my code is as follows:
 
  	  | Code: |  	  | #include <16F636.h>
 #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
 #FUSES NOPROTECT                //Code not protected from reading
 #FUSES NOCPD                    //No EE protection
 #FUSES NOMCLR                     //Master Clear pin enabled
 #FUSES NOIESO                     //Internal External Switch Over mode enabled
 #FUSES PUT                    //No Power Up Timer
 #FUSES NOFCMEN                    //Fail-safe clock monitor enabled
 #FUSES WURE                   //Wake-up and continue
 #FUSES NOBROWNOUT                 //Reset when brownout detected
 
 #use delay(clock=8000000)
 
 #use fast_io(A)
 #use fast_io(C)
 
 #define SW4         PIN_A0   // input
 #define SW3         PIN_A1   // input
 #define SW2         PIN_A3   // input
 #define SW1         PIN_A4   // input
 #define LED         PIN_A5   // output
 
 void main(void)
 {
 setup_oscillator(OSC_8MHZ);
 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
 setup_timer_1(T1_DISABLED);
 setup_comparator(NC_NC_NC_NC);
 setup_vref(FALSE);
 
 set_tris_a(0b00011111);                                       // set data I/O directions
 
 port_a_pullups(0b00011011);
 output_low(LED);
 while (TRUE)
 {
 if (!input(SW1))
 {
 output_high(led);
 delay_ms(100);
 output_low(led);
 delay_ms(100);
 }
 else if (!input(SW2))
 {
 output_high(led);
 delay_ms(500);
 output_low(led);
 delay_ms(500);
 }
 else if (!input(SW3))
 {
 output_high(led);
 delay_ms(1500);
 output_low(led);
 delay_ms(1500);
 }
 else if (!input(SW4))
 {
 output_high(led);
 delay_ms(3000);
 output_low(led);
 delay_ms(3000);
 }
 }
 }
 
 | 
 
 The result is that the Led blinks like if the button 1 was pressed, if I change the pull up in the SW4 the result is that like the button 3 was pressed...
 I've also tested with "no fast_io" but the problem is similar.
 I think that I have the fuses and the initialization correct...
 Does anyone have a clue for the behavior?
 My PICC version is 4.0.65
 Regards,
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Sat Apr 05, 2008 3:01 pm |   |  
				| 
 |  
				| Your problem ought to be RA3. If you look at the data sheet 'register 4-3', the bit to control the pull up on this pin, is read only. This pin only has a pull-up on it, when it is configured for use as MCLR, not in normal use. You will have to add a pull-up resistor to this pin.
 Fix this, and see if the problem changes.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Mon Apr 07, 2008 12:53 pm |   |  
				| 
 |  
				| Dear Ttelmah 
 I've add an pull-up resistor on the RA3 as you said and the is the same. The only thing that changed is that the result is like the button 3 was pressed. And  I'm not pressing any button.
 Do you have any more ideas?
 Thanks
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Apr 07, 2008 1:04 pm |   |  
				| 
 |  
				| Strip down your program and test one button at a time.   Comment out the code for all other buttons during each test.    Comment out all the
 "else if" sections that refer to other buttons.
 |  | 
	
		|  | 
	
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Thu Apr 10, 2008 7:39 am |   |  
				| 
 |  
				| I've been doing several tests. At this moment I don´t know what is problem.
 With the following code and with the external pull up in the RA3. The led blinks as if the button 1 was pressed.
 
  	  | Code: |  	  | #include <16F636.h>
 #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
 #FUSES NOPROTECT                //Code not protected from reading
 #FUSES NOCPD                    //No EE protection
 #FUSES NOMCLR                     //Master Clear pin enabled
 #FUSES NOIESO                     //Internal External Switch Over mode enabled
 #FUSES NOPUT                    //No Power Up Timer
 #FUSES NOFCMEN                    //Fail-safe clock monitor enabled
 #FUSES NOWURE                   //Wake-up and continue
 #FUSES NOBROWNOUT                 //Reset when brownout detected
 
 #use delay(clock=8000000)
 
 #use fast_io(A)
 
 #define SW4         PIN_A0   // input
 #define SW3         PIN_A1   // input
 #define SW2         PIN_A3   // input
 #define SW1         PIN_A4   // input
 #define LED         PIN_A5   // output
 
 int16 delay_time = 0;
 
 void delay_func(void)
 {
 delay_ms(delay_time);
 }
 
 void switch_led(void)
 {
 output_high(led);
 delay_func();
 output_low(led);
 delay_func();
 }
 
 void main(void)
 {
 //setup_oscillator(OSC_8MHZ);
 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
 setup_timer_1(T1_DISABLED);
 setup_comparator(NC_NC_NC_NC);
 setup_vref(FALSE);
 
 set_tris_a(0b00011111);                                       // set data I/O directions
 
 port_a_pullups(0b00010111);
 while (TRUE)
 {
 if (!input(SW1))
 {
 delay_time = 100;
 switch_led();
 }
 else if (!input(SW2))
 {
 delay_time = 500;
 switch_led();
 }
 /*else if (!input(SW3))
 {
 delay_time = 1500;
 switch_led();
 }
 else if (!input(SW4))
 {
 delay_time = 3000;
 switch_led();
 }*/
 }
 }
 
 | 
 If I have only the button 2 (comment the if statement of the SW1), every time I press this button the led links correctly, if I don't press the button 2 the led doesn't links as it should be.
 According with my tests the port_a_pullups function doesn't change the behavior of the led. I've made several changes in the set_tris_a and in the port_a_pullups but the result is always the same.
 I'm thinking in send you the .lst file for you to see what could be wrong but  this file is a little big.
 I think that I can not use this micro 16F636.
 Best regards,
 |  | 
	
		|  | 
	
		| Matro Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Thu Apr 10, 2008 7:45 am |   |  
				| 
 |  
				| I can't see the "#FUSES NOLVP" in your code. Add it to your fuses settings.
 
 Matro.
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 10, 2008 11:53 am |   |  
				| 
 |  
				| The LVP/NOLVP fuse is not an option for the 16F636.   It's not in the list of available fuses given at the top of the 16F636.H file.   Also, the data
 sheet doesn't show a "PGM" pin in the pinout diagram for that PIC.
 |  | 
	
		|  | 
	
		|  |