CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Port B Output problem on PIC16F627A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JamieG
Guest







Port B Output problem on PIC16F627A
PostPosted: Fri Feb 05, 2010 9:01 am     Reply with quote

I have an RS232 controlled switch, the I/O pins control logic pins on some analog switches. An I/O pin goes Low when it receives a character on RS232.

I am having problems with 2 pins on Port B. RB4 and RB5 are constantly Low. I have been scratching my head for a while now. Can anyone help?
Code:

#include <16F627A.h>
#fuses INTRC_IO, WDT, PUT, NOLVP, BROWNOUT, NOCPD, NOPROTECT
#use delay(clock = 4000000)

#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, BRGH1OK, ERRORS)

#define flash PIN_A4
#define A PIN_A1
#define B PIN_A0
#define C PIN_A7
#define D PIN_A6
#define E PIN_B7
#define F PIN_B6
#define G PIN_B5
#define H PIN_B4

int input, output;

void initialisations(){
//CCP_OFF;
//OSC_4MHZ;
set_tris_a(0b00000000);
set_tris_b(0b00000000);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
}


#INT_RDA              //RS232 receive data available
void isr_rs232(){
input = getc();
if (input == 'O'){ input = getc(); if (input == 'F')input = getc(); if (input == 'F')output = 0;}
else if (input == '1') output = 1;
else if (input == '2') output = 2;
else if (input == '3') output = 3;
else if (input == '4') output = 4;
else if (input == '5') output = 5;
else if (input == '6') output = 6;
else if (input == '7') output = 7;
else if (input == '8') output = 8; 

switch (output)   {
case 0:
output_a(11111111); output_b(11111111); break;
case 1:
output_low(A); break;
case 2:
output_low(B); break;
case 3:
output_low(C); break;
case 4:
output_low(D); break;
case 5:
output_low(E); break;
case 6:
output_low(F); break;
case 7:
output_low(G); break;
case 8:
output_low(H); break;
            }
}

void main(){

initialisations();

output = 0;
output_a(11111111); output_b(11111111);

//printf("\rAudio Switcher v1");
   while(1){
   restart_wdt();
   output_high(flash);
   delay_ms(500);
   restart_wdt();
   output_low(flash);
    delay_ms(500);

   //... and wait for rs232 interrupt
   }
}
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Feb 05, 2010 9:35 am     Reply with quote

First of all I would not use "input" as a variable name as there is a function called input();

Secondly you can simplify your isr_rs232() routine.
Code:

input = getc();
if (input == 'O')
{
  input = getc();
  if (input == 'F')
    input = getc();
  if (input== 'F')
    input = 0;
}

switch (input) {
case 0:
  output_a(11111111); output_b(11111111); break;
case 1:
  output_low(A); break;
case 2:
  output_low(B); break;
case 3:
output_low(C); break;
case 4:
  output_low(D); break;
case 5:
  output_low(E); break;
case 6:
  output_low(F); break;
case 7:
output_low(G); break;
case 8:
  output_low(H); break;
}


Lastly,
output_a(11111111); output_b(11111111); will not do what you expect until you add 0b to make your values binary.

output_a(0b11111111); output_b(0b11111111);
Guest








PostPosted: Mon Feb 08, 2010 4:18 am     Reply with quote

Wayne_ wrote:


Lastly,
output_a(11111111); output_b(11111111); will not do what you expect until you add 0b to make your values binary.

output_a(0b11111111); output_b(0b11111111);


I knew I'd missed something silly.

The reason I converted the input character to an integer is because I am yet to implement an option link which will offset the output.

I appreciate your help, thank you very much.

Jamie
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group