Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Programming problem for PIC 16f877a

Status
Not open for further replies.

Rooney_04

Member level 2
Member level 2
Joined
Oct 2, 2010
Messages
42
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,577
hi
below is some programing code i did for binary sequence count. So i like to use push button as to count up and another push button to push down. So i would like how i can PIN_b0 and Pin_B1 as the input. how i can do that or the coding ?


#include <16F877a.h>
#include <stdio.h>
#include <stdlib.h>
#use delay(clock=20000000)
#fuses hs, noprotect, nowdt, nolvp
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=RS232,bits=8)

#byte portb=6
#byte portc=7
#byte portd=8



int k, datain;

void main()
{
k=0;

loop:

// Check Input
datain=input_b();

if( bit_test(datain,0) && !bit_test (datain,1) )
k++;
if( !bit_test(datain,0) && bit_test (datain,1) )
k--;

// Send Data to RS232
putc(k);
delay_ms(50);

goto loop;

}
 

i m using CCS compiler
 
  • Like
Reactions: Hyori

    Hyori

    Points: 2
    Helpful Answer Positive Rating
if ((input(PIN_E1) == 1) // for pin E1 as input :)

---------- Post added at 06:17 ---------- Previous post was at 05:55 ----------

you need some debouncing routine also for the switches :)
 

And get rid of the "goto" before it causes you problems!
Wrap the read/send routines in a while(1) loop instead.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top