Since the device has a RS-232 interface, it is fairly straight forward. You need another MAX232 RS-232 transceiver for the PIC side of the circuit.
IC MAX232
As well as a set of appropriate capacitors required by the MAX232. You may want to see if they have a RS-232 breakout board with a DB9, this would simply adding a RS-232 interface to future projects.
Also take a look at my RFID Technologies Group for sample code and example applications.
RFID Technologies Group
Here's a nice tutorial which covers implementing an RS-232 port on a PIC18F, the differences are minor with the PIC16F:
RS232 Communication using PIC18F4520′s USART – PIC Microcontroller Tutorial
The info should get you started in the right direction. If you encounter any problems just post them here.
BigDog
Here is a MikroC UART to LCD Project which contains most of the elements necessary to complete your project:
A PIC Serial LCD project.
A couple of tutorials:
Lab 4: Interfacing a character LCD
Lab 8: Asynchronous serial communication
You should have examples of all the required libraries to utilize in your project.
BigDog
int sum(int i, int j){
int totalsum;
totalsum = i + j;
return totalsum;
}
void main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0;
PORTB = 0xFF;
Lcd_Init();
Lcd_Out(1,1,sum(1,2));
}
Another question, do you think ISIS 7 have any devices that can be configured then sent some output such like RFID reader ?
I want this for testing to check whether my code is working properly or not.
Hi,
How should I write if I want pass the function value to Lcd_Out(,,function) instead pointer.
Because I want to pass my UART read value and print it out in LCD display.
I have made simple programming for LCD display 16x2.
However in the simulation, it doest show correct result.
Here's the attachment codes:
Code:int sum(int i, int j){ int totalsum; totalsum = i + j; return totalsum; } void main() { ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISB = 0; PORTB = 0xFF; Lcd_Init(); Lcd_Out(1,1,sum(1,2)); }
void main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0;
PORTB = 0xFF;
Lcd_Init();
if (UART1_Data_Ready()) //<------ Check if a character has been received before reading
Lcd_Out(1,1,UART1_Read());
while(1); //<------ Do not let the execution exit main()
}
As far as I know ISIS Proteus 7 does not have a RFID reader model. However, you could easily simulate a RFID reader with a RS-232 interface by using the virtual terminal and manually sending a RFID string to the PIC.
There are two reasons the above code fails to yield expected results.
1. The "void Lcd_Out(char row, char column, char *text)" expects to be passed a valid pointer to a character string and you are passing an integer value, the return type of sum.
2. There is a significant difference between the integer 1 and the character '1', while "int sum(int i, int j)" returns an integer, "char UART1_Read()" return an ASCII character.
I would recommend using "void Lcd_Chr(char row, char column, char out_char)" which accepts a single character value and outputs it at the specified cursor location as does Lcd_Out().
Example:
Code:void main() { ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISB = 0; PORTB = 0xFF; Lcd_Init(); if (UART1_Data_Ready()) //<------ Check if a character has been received before reading Lcd_Out(1,1,UART1_Read()); while(1); //<------ Do not let the execution exit main() }
Hope this example helps,
BigDog
I have successfully compile it but show incorrect results in the LCD display.
The display result shows shifted character in the LCD screen.
Example:
Actual result shows " 123" instead of "123"
Take note: I used IntToStr().
Prototype void IntToStr(int input, char *output);
Description Converts input signed integer number to a string. The output string has fixed width
of 7 characters including null character at the end (string termination). The output
string is right justified and the remaining positions on the left (if any) are filled with
blanks.
Parameters:
- input: signed integer number to be converted
- output: destination string
Requires Destination string should be at least 7 characters in length.
Example int j = -4220;
char txt[7];
...
IntToStr(j, txt); // txt is " -4220" (one blank here)
// LCD define
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
char *uart_rd;
char data;
void main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0;
PORTB = 0xFF;
UART1_Init(9600);
Delay_ms(100);
Lcd_Init();
Delay_ms(100);
while(1) {
if (UART1_Data_Ready()){ //<------ Check if a character has been received before reading
uart_rd = UART1_Read(); // read the received data,
UART1_Write(uart_rd);
Lcd_Out(1,1,uart_rd);
}
}
}
unsigned char uart_rd;
unsigned char data;
unsigned char temp[10];
unsigned char N = 0;
// LCD define
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
void main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0;
PORTB = 0xFF;
UART1_Init(9600);
Delay_ms(100);
Lcd_Init();
Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
Delay_ms(100);
do {
if (UART1_Data_Ready()){ //<------ Check if a character has been received before reading
uart_rd = UART1_Read(); // read the received data,
UART1_Write(uart_rd);
temp[N] = uart_rd;
N = N +1;
if (N == 9) // temp storing string
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1,temp);
}
}
} while(1);
}
if (N == 9) // temp storing string
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1,temp);
[COLOR="#FF0000"]N = 0;[/COLOR]
}
Looks like you are not resetting the counter N once the buffer has been written to the LCD.
Try:
Code:if (N == 9) // temp storing string { Lcd_Cmd(_LCD_CLEAR); Lcd_out(1,1,temp); [COLOR="#FF0000"]N = 0;[/COLOR] }
BigDog
Decades of experience.
BigDog
Well, another question, I dont know what's purpose of MAX232, the 1uF capacitors needed to be connected with some pins.
If 10uF capacitors used ,will it be fine ?
I have checked the datasheet, it doesn't indicate the purpose of implement capacitors ?
I thought purpose maybe for stabilizing/regulate the voltage.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?