Jump to content

Recommended Posts

Hi, I am trying to get digital input on a 16F688. I have tried both port A and port C, but can't seem to read digital input. My code is listed below. I am using port C3 as input, port C1 as output. BatMon.h has function prototypes only.

 

#include <system.h>
#include "BatMon.h"

#pragma DATA _CONFIG, _FCMEN_OFF & _INTOSCIO & _WDT_OFF & _BOD_OFF & _CP_OFF

volatile bit rtc	@PORTC.3;     // RA4 button

void main()
  {      
  HWInit();
  for(;;)
     {
     lrtc = readSW0();
     if(rtc == 1)
        ToggleRed();
     delay_s(1);
     }//for(ever)
  }//main


void HWInit(void)
  {
  adcon1 = 0x08;					
  trisc = 0x08; 
  }//HWInit

void ToggleRed(void)
  {
  static char flag = 1;
  if(flag == 0)
     {
     flag = 1;
     set_bit(portc, 1);
     }
  else
     {
     flag = 0;
     clear_bit(portc, 1);
     }//if-then-else   
  }//ToggleRed

 

Does this code look OK? Is there anything anyone can see that is obviously wrong?

 

Thanks,

Shayne

Share this post


Link to post
Share on other sites

Shayne,

 

First of all appologies - I accidently deleted one of your posts by mistake, I was cleaning up as you posted the same thing multiple times, and I press the wrongs buttons :(

 

Your code looks OK, have you tried running its under the SourceBoost Debugger (you will probably want to reduce you delay or you will have to wait a long time)?

 

Also with your code as it is you will need to press the button for upto a second before you get a change.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Shayne,

 

First of all appologies - I accidently deleted one of your posts by mistake, I was cleaning up as you posted the same thing multiple times, and I press the wrongs buttons  :(

 

Your code looks OK, have you tried running its under the SourceBoost Debugger (you will probably want to reduce you delay or you will have to wait a long time)?

 

Also with your code as it is you will need to press the button for upto a second before you get a change.

 

Regards

Dave

 

 

Thanks for the reply. I have been running the code on a 16F819 device. Just as a test, I built a board with a 16F689 and got the same results. I ran the code in the debugger and it seems to be OK, it just doesn't seem to run in hardware. I wonder if my circuit design is to blame, but I seem to get appropriate transitions on the pins when I monitor them with a scope. I'm at a loss... I thought perhaps I'd try writing a function in assembly to test the switch.

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×