Hola que tal a todos, soy nuevo en el foro y nuevo en esto de la electrónica.
Tengo un proyecto donde necesito grabar solo 400 posiciones, separadas 10 ms cada una, de un encoder incremental en CCS e imprimirlas en el hyperterminal.
Aquí esta mi código, haber si alguien me puede indicar que estoy haciendo mal, por favor:
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL4,CPUDIV1,VREGEN
#use delay(clock=48000000)
#include "usb_cdc.h"
#byte porta=0xf80
#byte portb=0xf81
#byte portc=0xf82
#byte portd=0xf83
#byte porte=0Xf84
#byte PIR1=0xf9E
#byte INTCON= 0xff2
#byte INTCON2= 0xff1
#byte INTCON3= 0xff0
signed int16 posicion[400];
signed int16 posicion_pendulo;
unsigned int x=0;
int end_flag=0;
#INT_EXT1
void encoder_pendulo()
{
// bit_clear(INTCON,1);
if(bit_test(portb,2)) // Si hay entrada por el pin B2
{
posicion_pendulo++; // Aumenta posicion
}
else
{
posicion_pendulo--; // Decrementa posicion
}
}
#INT_TIMER1
void task_timer()
{
set_timer1(7000);
posicion[x] = posicion_pendulo; // Guarda la posicion
if (x==399) // Si se cumple esto se encenderan ambos les (Azul y ambar)
{
x=0;
disable_interrupts (global);
end_flag=1;
}
else
{
x++; // Aumenta variable x
}
}
void main(void)
{
set_tris_a(0b00000001);
set_tris_b(0b11000111);
set_tris_c(0b00010000);
set_tris_d(0b10000100);
set_tris_e(0b00000000);
portb=0x00;
portd=0X00;
portc=0x00;
portd=0x00;
porte=0x00;
enable_interrupts(INT_TIMER1);
enable_interrupts (INT_EXT1);
enable_interrupts(GLOBAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
set_timer1(7000);
while (end_flag==0);
output_high (PIN_D3); // Led Azul
Output_high (PIN_D4); // Led Ambar
usb_cdc_init();
usb_init();
while(!usb_cdc_connected()){}
do
{
usb_task();
if (usb_enumerated())
{
x=0;
for(x=0;x<=399;x++)
{
output_high (PIN_D6); //Led verde
printf(usb_cdc_putc, "%Ld\r\n",posicion[x]);
}
}
} while (TRUE);
}