i am quite new to microcontroller programming but i do understand basic configuration methods and able to code.I am trying to interface pic18f4550 with a magnetic card reader that uses rs232 connection.i connected the microcontroller and the card reader using a sp233ACP line driver which connects the card reader to the microcontroller.i am trying to receive data from the card reader to microcontroller and the microntroller will do a function(e.g when card is inserted into card reader,the microcontroller processes a new function and when card is taken out it performs another function).However,i cant receive any data from the card reader when i insert the card.I suspect it is my coding that has some problems but i cant seem to figure out the cause.In the code,i made it to turn on the LED in port D once the card was inside.The link to the magnetic card reader specification is https://www.dropbox.com/s/orvgc30fkkmehf5/WBM-1300 Specification.pdf?dl=0.I have tried all my best and have referred to all sources but they all bear no fruit.Following is the code that i implemented:
Moderators note: Please use code tags for pieces of code
Code:
#include <p18F4550.h>
#include <delays.h>
// Include this when using Bootloader Program ================================
#pragma udata
extern void _startup (void); // See c018i.c in your C18 compiler dir
#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808
void _high_ISR (void)
{
;
}
#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
{
;
}
#pragma code
#pragma code
// Ends here ===============================================================
// Program starts here:
void main(void)
{
// =======================================
ADCON1 = 0x0F;
CMCON = 0x07;
// ========================================
//TRISCbits.TRISC6=0;
TRISCbits.TRISC7=1;
RCSTA=0x90;
TXSTA=0x00;
SPBRG=77;
//t=0;
//r=0;
while(1) //repeat
{
//if(PIR1bits.TXIF==1);
{
//TXREG=data_out[t];
//t++;
}
if(PIR1bits.RCIF==1)
{
PORTD = 0b00000001; // turn on LED at _____
Delay10KTCYx (250); // for a while
PORTD = 0b00000010; // turn on LED at _____
Delay10KTCYx (250); // for a while
//data_in[r]=RCREG;
//r++;
}
Delay10KTCYx(250); //LEDs on for a while
Delay10KTCYx(250);
}
}
Last edited by a moderator: