Jump to content
Sign in to follow this  
rickson

Microcontroller 16f877

Recommended Posts

HI,

I'm currently using a microcontroller 16f877A. The Tx and Rx pins of my microcontroller will output either 1 or 0 respectively. The microcontroller is connected to my laptop using RS232-USB converter. The microcontroller has been programmed and the connection was tested. May i know what is the code to determine the output for Tx and Rx using VB? Because what i would like to do for my project is when the Tx output is 1, then some operation will be running and same for the Rx...

 

 

Below is roughly what my microcontroller will do:

#if pin no 19 & 20 at PIC is 0, then will make pin no 25 & 26 as 0 (output), so it wont activate your visual basic

#if pin no 19 at PIC is 1, then will make pin no 25 as 1 (output)so, activate visual basic due to first sensor

#if pin no 20 at PIC is 1, then will make pin no 26 as 1 (output) so activate visual basic due to second sensor

 

So, may i know whether my microcontroller code is correct as below?

 

void main()

{

trisd=1; // set port d as input

trisc=0; // set port c as output

portd=1; // initialize port d as 0

portc=1; // initialize port c as 0

while(1) {

if (portd== 0b00000000) // if pin no 19 & 20 at PIC is 0, then will

{ // make pin no 15 & 16 as 0 (output)

portc=0x00; // so it wont activate your visual basic

}

 

if (portd== 0b00000001) // if pin no 19 at PIC is 1, then will

{ // make pin no 25 as 1 (your output)

portc.f6=1; // activate visual basic due to first sensor

}

 

if (portd== 0b00000010) // if pin no 20 at PIC is 1, then will

{ // make pin no 26 as 1 (your output)

portc.f7=1; // activate visual basic due to second sensor

}

 

if (portd== 0b00000011) // if pin no 19 & 20 at PIC is 1, then will

{ // make pin no 15 & 16 as 1 (your output)

portc=0b00000011; // activate visual basic due to both sensors

}

}

 

}

 

Thanks.

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 emoticons maximum 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  

×