Recent Posts

Blogroll

                                          My PIC12F683 Development Board
Office Map Circuit diagram for each experiment may not be available separately because they are conducted with PIC12F683 development board that I made. So, the readers should first see the schematic of my development board.

Saturday, April 3, 2010

Experiment No. 2: User Inputs from Tact Switches and Software UART

In this experiment, we will demonstrate how to read inputs from tact switches, and then will also show how to send character data from PIC12F683 to a desktop PC Hyper-Terminal program through UART communication. Remember that PIC12F683 doesn't have hardware UART module, so we are going to use the Soft_UART library routines from mikroC for this purpose. Regarding the Hyper-Terminal setup on PC, read this. Besides, to read the user inputs from tact switches, Button Library routines in mikroC will be used.
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:

yannikajiwara said...

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

Online Embedded Systems Lab

This online laboratory teaches you the fundamentals of microcontroller-based embedded system development through a series of laboratory exercises. Most of the time, students and hobbyists could not afford expensive development kits and software to learn these things. These tutorials are prepared such that you will be building microcontroller projects at a minimum cost. Check this out