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 CCS Technical Support

RS232 communication

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



Joined: 07 Aug 2007
Posts: 24

View user's profile Send private message

RS232 communication
PostPosted: Mon Aug 13, 2007 7:37 am     Reply with quote

Hey,

Currently i am using a program on VB to turn on/0ff pins on a microcontroller.

Does anyone have an idee how to write this code in CCS?

Code:


Main:

' Use the programming port to receive
' data at 2400 baud
' Wait for the synch byte (255) and then
' get the PinNumber and PinState
Serin 16,16780,[WAIT(255),PinNumber,PinState]

' If PinState=0 Then go to GoLow
' otherwise go to GoHigh
Branch PinState,[GoLow,GoHigh]
Goto Main


' Set The pin low
GoLow:
LOW PinNumber
Goto Main


' Set the pin high
GoHigh:
HIGH PinNumber
Goto Main

ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 13, 2007 8:09 am     Reply with quote

Code:
#include <18F458.h>
#fuses HS, NOWDT, PUT, NOLVP
#use delay(clock=16000000)
#use rs232 (baud=2400, xmit=PIN_C6, rcv=PIN_C7, ERRORS)


void wait_pin_command()
{
  int8 PinNumber;
  int8 PinState;
 
  while (getc() != 255)
    ; // wait for the synch byte
 
  PinNumber = getc();
  PinState = getc();

  if (PinState == 0)
  {
    output_low(PinNumber);
  }
  else
  {
    output_high(PinNumber);
  }
}

void main()
{
  while (TRUE)
  {
    wait_pin_command();
  }
}
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