domingo, 29 de junho de 2014

Exemplo de Circuitos ADC com PIC18f4550







EXEMPLO 1


//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014
//ExerciseADC1:Display Voltage Percentage and Temperature
#include <18f4550.h> //Header File
#fuses HS, NOWDT, NOLVP, NOPROTECT //Hardware Configuration
#device ADC=10 //Select 10 bit resolution
#use delay(clock=20M)
#include <lcd.c> //Driver for LCD
//Pin Definitions for LCD
#define   LCD_ENABLE_PIN   PIN_D0
#define   LCD_RS_PIN       PIN_D1
#define   LCD_RW_PIN       PIN_D2
#define   LCD_DATA4        PIN_D4
#define   LCD_DATA5        PIN_D5
#define   LCD_DATA6        PIN_D6
#define   LCD_DATA7        PIN_D7
//Main Function
void main(){
   //Variable declaration
   int32 value1, voltage, value2, temp, percent;
   //initialize LCD
   lcd_init();
   //ADC configuration
   setup_ADC(ADC_CLOCK_INTERNAL);
   setup_ADC_ports(ALL_ANALOG);
   while(true){
      //Program Start Here
      //Voltage
      set_adc_channel(0);
      value1=read_adc(); //Read analog signal
      voltage=value1*5/(1024-1); //Calculate conversion
      //Percentage
      percent=value1*100/(1024-1); //Calculate conversion
      //Temperature Sensor LM35
      set_adc_channel(1);
      value2=read_adc(); //Read analog signal
      temp=value2*5*100/1023; //Conversion
        
      //Display on LCD
      printf(lcd_putc,"\fVoltage = %dV",(int)voltage);
      printf(lcd_putc,"\nPercentage=%d%%",(int)percent);
      delay_ms(500);
      printf(lcd_putc,"\fSuhu=%.2f Degree",(float)temp);
      delay_ms(500);
   }
}
 
//**********************************************************
 

EXEMPLO 2


//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014
//Exemplo 2 ADC2: 3 LEDs will turn ON base on temperature
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#device ADC=10
#use delay(clock=20M)
#include <lcd.c>
//Pin Definition
//Pin Definitions for LCD
#define   LCD_ENABLE_PIN   PIN_D0
#define   LCD_RS_PIN       PIN_D1
#define   LCD_RW_PIN       PIN_D2
#define   LCD_DATA4        PIN_D4
#define   LCD_DATA5        PIN_D5
#define   LCD_DATA6        PIN_D6
#define   LCD_DATA7        PIN_D7
 
//Pin Definition for LED
#define   RED      PIN_C0
#define   YELLOW   PIN_C1
#define   GREEN    PIN_C2
 
//Main Function
void main(){
   int32 value1, temperature;
  
   lcd_init();

   //Set PORT C as output
   set_tris_c(0x00);
   output_c(0x00); //Initialize PORT C
  
   //ADC configuration
      setup_ADC(ADC_CLOCK_INTERNAL);
      setup_ADC_ports(ALL_ANALOG);
   while(true){
      //Read Analog Signal
      set_adc_channel(1);
      value1=read_adc();
      temperature=value1*100*5/1023;
     
      if(temperature>=100){
  printf(lcd_putc,"\fSuhu Alert \n%.2f Celcius",(float)temperature);
         output_high(RED);
         output_low(YELLOW);
         output_low(GREEN);
         delay_ms(500);
      }
      else if(temperature<=95&&temperature>=25){
 printf(lcd_putc,"\fSuhu Normal \n%.2f Celcius",(float)temperature);
         output_low(RED);
         output_high(YELLOW);
         output_low(GREEN);
         delay_ms(500);  
      }
      else if(temperature<=20){
     printf(lcd_putc,"\fSuhu Low\n%.2f Celcius",(float)temperature);
         output_low(RED);
         output_low(YELLOW);
         output_high(GREEN);
         delay_ms(500);  
      }
   }
}

//**********************************************************



EXEMPLO 3


//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014
//Exemplo 3 ADC3 : Manipulating LCD for displaying ADC
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#device ADC=10
#use delay(clock=20M)
#include <lcd.c>
//Pin Definition
//Pin Definitions for LCD
#define   LCD_ENABLE_PIN   PIN_D0
#define   LCD_RS_PIN       PIN_D1
#define   LCD_RW_PIN       PIN_D2
#define   LCD_DATA4        PIN_D4
#define   LCD_DATA5        PIN_D5
#define   LCD_DATA6        PIN_D6
#define   LCD_DATA7        PIN_D7
//Main Function
void main(){
   //Variable declaration
   int32 value1, voltage, value2, temp, percent;
   //initialize LCD
   lcd_init();
   //ADC configuration
   setup_ADC(ADC_CLOCK_INTERNAL);
   setup_ADC_ports(ALL_ANALOG);
   while(true){
      //Program Start Here
      //Voltage
      set_adc_channel(0);
      value1=read_adc(); //Read analog signal
      voltage=value1*5/(1024-1); //Calculate conversion
      //Percentage
      percent=value1*100/(1024-1); //Calculate conversion
      //Temperature Sensor LM35
      set_adc_channel(1);
      value2=read_adc(); //Read analog signal
      temp=value2*5*100/1023; //Conversion
        
      //Display on LCD
      printf(lcd_putc,"\fVoltage = %dV",(int)voltage);
      delay_ms(500);
      printf(lcd_putc,"\fSuhu=%.2f Degree",(float)temp);
      delay_ms(500);
   }
}

//**********************************************************


EXEMPLO 4


//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014                       
//Exemplo 4 ADC4: Controlling Motor via ADC
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#device ADC=10
#use delay(clock=20M)
#include <lcd.c>

//Pin Definitions for LCD
#define   LCD_ENABLE_PIN   PIN_D0
#define   LCD_RS_PIN       PIN_D1
#define   LCD_RW_PIN       PIN_D2
#define   LCD_DATA4        PIN_D4
#define   LCD_DATA5        PIN_D5
#define   LCD_DATA6        PIN_D6
#define   LCD_DATA7        PIN_D7
//Pin Definition for LED
#define   Motor1_L      PIN_C4
#define   Motor1_R      PIN_C5
#define   Motor2_L      PIN_C6
#define   Motor2_R      PIN_C7

//Main Function
void main(){
   int32 value1, voltage;
  
   lcd_init();
   //Set PORT C as output
   set_tris_c(0x00);
   output_c(0x00); //Initialize PORT C
  
   //ADC configuration
      setup_ADC(ADC_CLOCK_INTERNAL);
      setup_ADC_ports(ALL_ANALOG);
   while(true){
      //Read Analog Signal
      set_adc_channel(0);
      value1=read_adc();
      voltage=value1*5/1023;
     
      if(voltage>=3){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_high(Motor1_L);
         output_low(Motor1_R);
         output_low(Motor2_L);
         output_low(Motor2_R);
         delay_ms(500);
      }
      else if(voltage<=2){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_low(Motor1_L);
         output_low(Motor1_R);
         output_high(Motor2_L);
         output_low(Motor2_R);
         delay_ms(500);  
      }
      else{
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_low(Motor1_L);
         output_low(Motor1_R);
         output_low(Motor2_L);
         output_low(Motor2_R);
         delay_ms(500);  
      }
   }
}

//**********************************************************

EXEMPLO 5


//**********************************************************
///                     Daniel Wagner                   
///                      29/06/2014                       
//Exemplo 5 ADC5: Controlling LED bargraph
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#device ADC=10
#use delay(clock=20M)
#include <lcd.c>
//Pin Definition
//Pin Definitions for LCD
#define   LCD_ENABLE_PIN   PIN_D0
#define   LCD_RS_PIN       PIN_D1
#define   LCD_RW_PIN       PIN_D2
#define   LCD_DATA4        PIN_D4
#define   LCD_DATA5        PIN_D5
#define   LCD_DATA6        PIN_D6
#define   LCD_DATA7        PIN_D7

//Main Function
void main(){
   int32 value1, voltage;
  
   lcd_init();

   //Set PORT B as output
   set_tris_b(0x00);
   output_b(0x00); //Initialize PORT C
  
   //ADC configuration
      setup_ADC(ADC_CLOCK_INTERNAL);
      setup_ADC_ports(ALL_ANALOG);
   while(true){
      //Read Analog Signal
      set_adc_channel(0);
      value1=read_adc();
      voltage=value1*5/1023;
   
   if(voltage==0){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_b(0);
         delay_ms(500);
      }
      else if(voltage==1){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_b(3);
         delay_ms(500);  
      }
      else if(voltage==2){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_b(15);
         delay_ms(500);  
      }
   else if(voltage==3){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_b(31);
         delay_ms(500);  
      }
   else if(voltage==4){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_b(63);
         delay_ms(500);  
      }
   else if(voltage==5){
         printf(lcd_putc,"\fVoltage \n%dV",(int)voltage);
         output_b(255);
         delay_ms(500);  
      }
   }
}

Exemplos de Controle de Motor DC com PIC18f4550

 
 

Exemplo do circuito de testes

 
Os exemplos abaixo são utilizados para controle de motor DC, são 5 exemplos que demonstram diversas maneiras de controle.

Códigos:

EXEMPLO 1

 
//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014 

//Exemplo 1 Motor.c : Controlling Direction of MotorA and MotorB
#include <18f4550.h> // Header file
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock = 20M)
// Pin Definition
#define MOTORA_1     PIN_B0 //IN1
#define MOTORA_2     PIN_B1 //IN2
#define MOTORB_1     PIN_B2 //IN3
#define MOTORB_2     PIN_B3 //IN4
void main(){
     //Set PORTB as output
     set_tris_b(0x00);
 
     //Configure PWM Pinout
     setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION
     while(true){
           //Turn On Motor A CW
           output_high(MOTORA_1);
           output_low(MOTORA_2);
 
           //Turn On Motor B CCW
           output_low(MOTORB_1);
           output_high(MOTORB_2);
     }
 
}

 

 
//*************************************************************


EXEMPLO 2

 
//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014 
//Exemplo 2 Motor.c : Controlling Speed of MotorA and MotorB
#include <18f4550.h7gt; // Header file
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock = 20M)
// Pin Definition
#define MOTORA_1     PIN_B0 //IN1
#define MOTORA_2     PIN_B1 //IN2
#define MOTORB_1     PIN_B2 //IN3
#define MOTORB_2     PIN_B3 //IN4
void main(){
     //Set PORTB as output
     set_tris_b(0x00);
 
     //Configure PWM Pinout
     setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION
     while(true){
           //Turn On Motor A CW
           output_high(MOTORA_1);
           output_low(MOTORA_2);
           set_pwm1_duty(200); //Speed of MotorA
 
           //Turn On Motor B CCW
           output_low(MOTORB_1);
           output_high(MOTORB_2);
           set_pwm2_duty(150); //Speed of MotorB
     }
 
}

 

 
//*************************************************************


EXEMPLO 3

 
//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014 
 
//Exemplo 3 Motor.c : Controlling Motor using Buttons
#include <18f4550.h> // Header file
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock = 20M)
#include <lcd.c>
//Pin Definition for LCD
#define LCD_ENABLE_PIN     PIN_D0
#define LCD_RS_PIN         PIN_D1
#define LCD_RW_PIN         PIN_D2
#define LCD_DATA4          PIN_D4
#define LCD_DATA5          PIN_D5
#define LCD_DATA6          PIN_D6
#define LCD_DATA7          PIN_D7
 
//Pin Definition for Buttons
#define    BUTTON1    PIN_B4
#define    BUTTON2    PIN_B5
 
// Pin Definition For Motor
#define MOTORA_1     PIN_B0 //IN1
#define MOTORA_2     PIN_B1 //IN2
#define MOTORB_1     PIN_B2 //IN3
#define MOTORB_2     PIN_B3 //IN4
void main(){
     //Set PINB0-PINB3 as output PINB4-PINB7 as input
     set_tris_b(0xF0);
 
     lcd_init();
 
     //Configure PWM Pinout
     setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION
     while(true){
 
           if(!input(BUTTON1)){
                //Turn On Motor A MotorB turn Off
                output_high(MOTORA_1);
                output_low(MOTORA_2);
                output_high(MOTORB_1);
                output_high(MOTORB_2);
                set_pwm1_duty(100); //Speed of MotorA
                printf(lcd_putc,”\fMOTORA Move\nMOTORB Stop”);
                delay_ms(100);
           }
           else if(!input(BUTTON2)){
                output_high(MOTORA_1);
                output_high(MOTORA_2);
                output_high(MOTORB_1);
                output_low(MOTORB_2);
                set_pwm2_duty(100);
                printf(lcd_putc,”\fMOTORA Stop\nMOTORB Move”);
                delay_ms(100);
           }
           else {
                output_high(MOTORA_1);
                output_high(MOTORA_2);
                output_high(MOTORB_1);
                output_high(MOTORB_2);
                printf(lcd_putc,”\fMOTORA Stop\nMOTORB Stop”);
                delay_ms(100);
           }
     }
 
}
 
//*************************************************************

 


EXEMPLO 4

 
//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014 
//Exemplo4 Motor.c : Controlling Speed of Motor using Buttons
#include <18f4550.h> // Header file
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock = 20M)
#include <lcd.c>
//Pin Definition for LCD
#define LCD_ENABLE_PIN     PIN_D0
#define LCD_RS_PIN         PIN_D1
#define LCD_RW_PIN         PIN_D2
#define LCD_DATA4          PIN_D4
#define LCD_DATA5          PIN_D5
#define LCD_DATA6          PIN_D6
#define LCD_DATA7          PIN_D7
 
//Pin Definition for Buttons
#define    BUTTON1    PIN_B4
#define    BUTTON2    PIN_B5
 
// Pin Definition For Motor
#define MOTORA_1     PIN_B0 //IN1
#define MOTORA_2     PIN_B1 //IN2
#define MOTORB_1     PIN_B2 //IN3
#define MOTORB_2     PIN_B3 //IN4
void main(){
     int32 speed=50; //Speed of motor
     //Set PINB0-PINB3 as output PINB4-PINB7 as input
     set_tris_b(0xF0);
 
     lcd_init();
 
     //Configure PWM Pinout
     setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION
     while(true){
 
           if(!input(BUTTON1)){
                speed++;
                output_high(MOTORA_1);
                output_low(MOTORA_2);
                output_high(MOTORB_1);
                output_low(MOTORB_2);
                set_pwm1_duty(speed); //Speed of MotorA
                set_pwm2_duty(speed);
                printf(lcd_putc,”\fSpeed = %ld”,speed);
                delay_ms(100);
           }
           else if(!input(BUTTON2)){
                speed--;
                output_high(MOTORA_1);
                output_low(MOTORA_2);
                output_high(MOTORB_1);
                output_low(MOTORB_2);
                set_pwm1_duty(speed); //Speed of MotorA
                set_pwm2_duty(speed);
                printf(lcd_putc,”\fSpeed = %ld”,speed);
                delay_ms(100);
           }
           if(speed>=200){
                speed=200;
           }
           else if(speed<=20){
                speed=20;
           }
     }
 
}
//**********************************************************


 

EXEMPLO 5

 
//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014 
//Exemplo5Motor.c : Controlling Speed of Motor using Potentiometer
#include <18f4550.h> // Header file
#fuses HS, NOWDT, NOPROTECT, NOLVP
#device ADC=10
#use delay (clock = 20M)
#include <lcd.c>
//Pin Definition for LCD
#define LCD_ENABLE_PIN     PIN_D0
#define LCD_RS_PIN         PIN_D1
#define LCD_RW_PIN         PIN_D2
#define LCD_DATA4          PIN_D4
#define LCD_DATA5          PIN_D5
#define LCD_DATA6          PIN_D6
#define LCD_DATA7          PIN_D7
 
//Pin Definition for Buttons
#define    BUTTON1    PIN_B4
#define    BUTTON2    PIN_B5
 
// Pin Definition For Motor
#define MOTORA_1     PIN_B0 //IN1
#define MOTORA_2     PIN_B1 //IN2
#define MOTORB_1     PIN_B2 //IN3
#define MOTORB_2     PIN_B3 //IN4
void main(){
     int32 speed=250; //Speed of motor
     int32 value;
     //Set PINB0-PINB3 as output PINB4-PINB7 as input
     set_tris_b(0xF0);
     lcd_init();
 
     //Configure Analog Input
     setup_adc_ports (ALL_ANALOG);
     setup_adc (ADC_CLOCK_INTERNAL);
 
     //Configure PWM Pinout
     setup_timer_2(T2_DIV_BY_4,254,1);//PWM OUTPUT CONFIGURATION
setup_ccp1(ccp_pwm); //PWM 1 DUTY CYCLE CONFIGURATION
setup_ccp2(ccp_pwm); //PWM 2 DUTY CYCLE CONFIGURATION
     while(true){
 
        set_adc_channel(2);
         value=read_adc();
         value=value*100/1023;
        
         if(value>=80)
         {           
            speed = speed+10;
            delay_ms(100);
         }
         else if (value<=30)   
         {
            speed = speed-10;
            delay_ms(100);
         }
        
         if (speed >= 100)
         {
            speed = 100;
         }
         else if(speed<=2)
         {
            speed=2;        
         }
        
         output_high(MOTORA_1);
         output_low(MOTORA_2);
         output_high(MOTORB_1);
         output_low(MOTORB_2);
         set_pwm1_duty(speed);
         set_pwm2_duty(speed);
         printf(lcd_putc,"\fSPEED %ld",speed);
         printf(lcd_putc,"\nPercentage=%d%%",(int)value);        
         delay_ms(10); 
   }
 
}

 

Exemplo de um Programa utilizando Keypad 4x4

Exemplo de um Programa utilizando Keypad 4x4



 
 

Exemplo 1


 
 

EXEMPLO 1


//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014

//Keypad Driver: flex_kbd4x4.c

#define row0 PIN_B4 
#define row1 PIN_B5 
#define row2 PIN_B6 
#define row3 PIN_B7 
#define col0 PIN_B0 
#define col1 PIN_B1 
#define col2 PIN_B2 
#define col3 PIN_B3 

// Keypad layout: 
char const KEYS[4][4] = 
{{'7','8','9','/'}, 
 {'4','5','6','X'}, 
 {'1','2','3','-'}, 
 {'*','0','=','+'}}; 


#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where 
// n is the number of times you expect 
// to call kbd_getc each second 

void kbd_init() 
//set_tris_b(0xF0); 
//output_b(0xF0); 
port_b_pullups(true);  

short int ALL_ROWS (void) 
if(input (row0) & input (row1) & input (row2) & input (row3)) 
   return (0); 
else 
   return (1); 



char kbd_getc() 
static byte kbd_call_count; 
static short int kbd_down; 
static char last_key; 
static byte col; 

byte kchar; 
byte row; 

kchar='\0'; 

if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) 
  { 
   switch (col) 
     { 
      case 0: 
        output_low(col0); 
        output_high(col1); 
        output_high(col2); 
        output_high(col3); 
        break; 
    
      case 1: 
        output_high(col0); 
        output_low(col1); 
        output_high(col2); 
        output_high(col3); 
        break; 

      case 2: 
        output_high(col0); 
        output_high(col1); 
        output_low(col2); 
        output_high(col3); 
        break; 

      case 3: 
        output_high(col0); 
        output_high(col1); 
        output_high(col2); 
        output_low(col3); 
        break; 
      } 

   if(kbd_down) 
     { 
      if(!ALL_ROWS()) 
        { 
         kbd_down=false; 
         kchar=last_key; 
         last_key='\0'; 
        } 
     } 
   else 
     { 
      if(ALL_ROWS()) 
        { 
         if(!input (row0)) 
            row=0; 
         else if(!input (row1)) 
            row=1; 
         else if(!input (row2)) 
            row=2; 
         else if(!input (row3)) 
            row=3; 

         last_key =KEYS[row][col]; 
         kbd_down = true; 
        } 
      else 
        { 
         ++col; 
         if(col==4) 
            col=0; 
        } 
     } 
   kbd_call_count=0; 
  } 
return(kchar); 

//**********************************************************
 
//Main Program
#include <18F4550.h> // PIC18F4550 HEADER FILE
#fuses XT,NOWDT,NOLVP,NOPROTECT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE 
#device adc=10 // USE 10 BIT ADC QUANTIZATION
#use delay (clock=4M) // 4 MHZ CRYSTAL

#include <flex_lcd420.c>
#include <flex_kbd4x4.c>


//Main Program

void main()
{  
   char k;
   
   lcd_init();
   kbd_init();

   lcd_putc("\fReady...\n");
   //Pin Configuration
   
   while(true)
   {
      //Program start here
      k=kbd_getc();
      if(k!=0)
        if(k=='*')
         {
          lcd_putc('\f');
          delay_ms(100);
          lcd_putc("\fReady...\n");
         }
        else
          lcd_putc(k);
   }

}

 

Exemplo de um Programa com Keypad 3x4

 

Exemplo de um Programa com Keypad 3x4 e PIC 18F4550

 
 

 

Figura exemplo 1


Segue o código fonte do circuito a cima, o mesmo foi testado no Protheus e compilado com o CCS.


EXEMPLO


//**********************************************************
///                     Daniel Wagner                     
///                      29/06/2014 
//Exemplo do Programa
#include <18F4550.h> // PIC18F4550 HEADER FILE

#fuses XT,NOWDT,NOLVP,NOPROTECT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE 
#device adc=10 // USE 10 BIT ADC QUANTIZATION
#use delay (clock=4M) // 4 MHZ CRYSTAL

 
#include <flex_lcd420.c>
#include <flex_kbd.c>


 

 
//Main Program

 
void main()
{  
   char k;
   
   lcd_init();
   kbd_init();

 
   lcd_putc("\fReady...\n");
   //Pin Configuration
   
   while(true)
   {
      //Program start here
      k=kbd_getc();
      if(k!=0)
        if(k=='*')
         {
          lcd_putc('\f');
          delay_ms(100);
          lcd_putc("\fReady...\n");
         }
        else
          lcd_putc(k);
   }

 
}