Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F84A, Problems capturing serial data using CCS compiler

Status
Not open for further replies.

Jkenyo10

New Member
Hi all, I am using a PIC16F84A to read data from a megnetic strip reader. The problem I have is trying to capture the first 11 characters to an array and then to display it on an LCD. The pic seems to be constantly reading the data even when I don't swipe. I need to create some kind of trigger so that it captures the data only when I swipe a card through.
I have made a program that displays all the card data on the LCD but without putting it in an array. I have also managed to isolate the first 11 characters but they are triangles (triangles appear on the LCD when there is no card being swiped but the pic is still reading in data). Does anyone know how to create somekind of trigger to capture the data only when it starts to recieve characters. The reader uses 9600 Baud and no handshaking. The program below is what I have so far and displays 11 triangles on the LCD screen. I am using a CCS compiler. I would be very grateful for any help. Thankyou very much. Jim Kenyon


// INPUT CARD DATA



#include <16f84a.h>
#include <ctype.h>
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A0,invert,stream=LCD) // Sets up RS232 Baud rate.
#use rs232(baud=9600, xmit=PIN_A2, rcv=PIN_A3,invert,stream=READER)

int i;
int a=254; // Defines the control signal 254 as a.
int b=1; // Defines the control signal 1 as b.
char data;
char matric [11]; //defining 11 characters in the array called matric.
main(){


delay_ms(1000); // pause 1 second.
fprintf(LCD,"PLEASE SWIPE CARD"); // prints to lcd.
delay_ms(3000); // pause 3 seconds.
printf("%c%c",a,b); // send control data as characters to lcd.
delay_ms(2000);



for(i=0;i<11;i++){
data=fgetc(READER);
fprintf(LCD,"%c",data);
//delay_ms(3000);



}
}
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top