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.

help me convert c to picbasic

Status
Not open for further replies.

daimellah

Newbie
Newbie level 1
Joined
Oct 11, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
#include <16F877.h>
#device ADC=8
#use delay(clock=20000000)
#fuses HS, NOWDT, PUT, NOPROTECT, BROWNOUT, NOLVP, CPD, NOWRT, NODEBUG
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, stream=sigPC)
#BYTE PORTB = 6
#use fast_io(A)
#use fast_io(B)
#include <stdlib.h>
#include <math.h>
#include <setjmp.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <input.c>

//getting the variables needed to 4 channels of PWM output from just standard IO ports
unsigned int x;
unsigned int i;
unsigned long y;
BYTE howmanyLoops[5] = {5,5,5,5,0}; //for the delay calculation //HighByte
BYTE remainder[5] = {220,220,220,220,0}; //LowByte
BYTE goalHowmanyLoops[5] = {5,5,5,5,0};

unsigned long finaldelay; //this is for the 20ms delay calculation
BYTE finaldelayRemainder;
BYTE buttonPressed = 0;

#define BUFFER_SIZE 3 //we want 3 Bytes
BYTE buffer[BUFFER_SIZE];
BYTE currentByte = 0;

BYTE j;

#int_rda
void serial_isr()
{
if (kbhit())
{
buffer[currentByte] = getc();
currentByte++;
if (currentByte == BUFFER_SIZE) //we have received all 3 BYTES do the array modifications
{
currentByte = 0;
j = buffer[0]-1; //find out which motor we want
goalhowmanyLoops[j] = buffer[1]; //move high byte
remainder[j] = buffer[2]; //remainder is directly modified....this isn't a big change }
}
}
}
#int_ext //INT_EXT is the external interrupt used for the push button when the player finishes his move

void switch_isr()
{
if (buttonPressed == 0)
{ buttonPressed = 1;}
else
{fprintf(sigPC, "P");
buttonPressed = 0;
}
}


main()
{
//fprintf(sigPC, "Initializing... \n\r");
set_tris_a(0xFF); //set all A registers as inputs
set_tris_b(0x01); //set all B as output
PORTB = 0 ; //set immediately B as zero to avoid servo jerking]

enable_interrupts(global);
enable_interrupts(int_ext);
enable_interrupts(INT_RDA);

while(1)
{
finaldelay = 20000;
for(x=0;x<4;x++) // step through the array and send out the data to b1-b6
{
bit_set(PORTB,x+4);

for (i=0; i<howmanyLoops[x]; i++)
{delay_us(256);}
delay_us(remainder[x]);

bit_clear(PORTB,x+4);

finaldelay = finaldelay - (howmanyLoops[x]*256) - remainder[x];

}
//handle electromagnet pickup signal
y = (unsigned int)remainder[4];
if (y)
bit_set(PORTB, 3); //setting B3 to be y
else
bit_clear(PORTB,3); //setting B3 to be y

for (i=1; i< (finaldelay >> 8); i++)
{delay_us(256);}

finaldelayRemainder = (finaldelay % 256);
delay_us(finaldelayRemainder);//this is adjustable

}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top