Snapshots of the required Library Routines from mikroC User's Manual
Setup:
The two switch inputs in our board will be connected to GP0 and GP1 port (Pins 7 and 6 respectively). GP5 (Pin 2) will be used for Software UART Tx. So here is what you need to do:
- Connect SW1 and SW2 (tact switches) to GP0 and GP1 using jumper wires,
- Connect GP5 to input Tx of TTL to RS232 Level Shifter circuit,
- Connect Rx(2) and Gnd(5) pins of a RS232 port to the board.
Software:
This code will detect which of the two tact switches is pressed and then send a message to the PC through UART, e.g. if SW1 is pressed, it will say "SW1 Pressed".
/*
PIC12F683 Experiment Board
Experimen No. 2 : Input from tact switches and send info to
desktop PC using Software UART.
Date: 04/03/2010
*/
char Message1[] = "SW1 Pressed";
char Message2[] = "SW2 Pressed";
char i, error;
void main() {
CMCON0 = 7;
TRISIO = 11; // GPIO 0, 1, 3 Inputs; Rest are O/Ps
ANSEL = 0;
GPIO = 0;
// Define GPIO.3 as UART Rx, and 5 as Tx
error = Soft_UART_Init(&GPIO,3, 5, 9600, 0 );
Delay_ms(100);
do {
if (Button(&GPIO, 0, 1, 0)) { // Detect logical one to zero
Delay_ms(300);
for (i=0; i<= 10; i++) {
Soft_UART_Write(Message1[i]);
Delay_ms(50);
}
Soft_UART_Write(10); // Line Feed
Soft_UART_Write(13); // Carriage Return
}
if (Button(&GPIO, 1, 1, 0)) { // Detect logical one to zero
Delay_ms(300) ;
for (i=0; i<= 10; i++) {
Soft_UART_Write(Message2[i]);
Delay_ms(50);
}
Soft_UART_Write(10); // Line Feed
Soft_UART_Write(13); // Carriage Return
}
} while(1);
}
Output:
1 comments:
Borgata Hotel Casino & Spa - Mapyro
Hotel Amenities. Spa. 평택 출장샵 Borgata is the perfect choice for families 대구광역 출장안마 looking for a relaxing and energetic vacation. 창원 출장마사지 Borgata 의왕 출장마사지 Hotel Casino & Spa 속초 출장마사지 has a
Post a Comment