/*
Author: Enslaved46
ECE :422
LAB : PWM signal generator with external keyboard interrupt and timer interrupt
*/
#include <18f4455.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //No Power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES NOLVP //No Low-Voltage ICSP Programming
#FUSES HSPLL // High-Speed Crystal with PLL enabled
#FUSES PLL5 //PLL prescaler set to 5
#FUSES CPUDIV1 //no postscaler
#use delay(clock = 48Mhz, crystal = 20Mhz)
#use RS232(UART1, BAUD=115200, PARITY=N, BITS=8, STOP=1, TIMEOUT = 500)
#define OUTPUT_PIN PIN_A3
#include "kbd_yz.c"
#include <lcd.c>
char key_p;
int key_flag=0;
Int16 TN;
#INT_RDA
void key_board(){
key_p=getc();
key_flag=1;
}
#INT_EXT
void key_pad(){
key_p=kbd_getc();
key_flag=1;
}
#INT_TIMER0
void waveform(){
output_toggle(OUTPUT_PIN);
set_timer0(TN + get_timer0());
}
void enable_board();
void reset();
void enable_keyp();
void main(){
int signal_flag=0;
Int16 temp=0;
Int16 time_us;//=0;
Int16 temp1 ;//=0;
lcd_init();
kbd_init();
printf(lcd_putc,"\f ASHISH KHADKA:\n");
enable_keyp();
//output_low(OUTPUT_PIN);
SETUP_TIMER_0(T0_INTERNAL | T0_DIV_1);
//
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
printf("\r\nEnter time mirco-second: ");
while(true){
if(key_p!=0&&key_flag==1){
disable_interrupts(INT_EXT);
temp1=key_p-'0';
key_flag=0;
switch(key_p){
default :
temp=(temp*10)+temp1;
// printf(" temp = %ld \n",temp);
printf(lcd_putc,"%c",key_p);
delay_us(20);
break;
case '*':
key_p=0;
key_flag=0;
temp=0;
time_us=0;
output_low(OUTPUT_PIN);
printf("Reset performed\n");
lcd_putc('\f');
printf(lcd_putc,"Enter time us: \n");
delay_us(20);
enable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER0);
signal_flag=0;
break;
case '#':
printf(" Entered time in us = %ld ",time_us);
time_us=(temp)/2;
signal_flag=1;
printf(lcd_putc,"\fperiod = %ld us ",temp);
delay_us(20);
TN = 65535 - time_us*12+12;
enable_interrupts(INT_TIMER0);
break;
}
}
reset();
}
}
void enable_board(){
clear_interrupt(INT_RDA); // register/output keep old values, need to be cleared
enable_interrupts(INT_RDA); // these 5 statements may be grouped in a function
}
void enable_keyp(){
// these 5 statements reset interrupt
// key_b=0;
set_tris_D(0x1E);
kbd=0x1E;
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
}
void reset() {
set_tris_D(0x01E); // Set column output, row input
kbd=0x1E; // Set all columns low, all rows high
clear_interrupt(INT_EXT); // register/output keep old values, need to be cleared
enable_interrupts(INT_EXT); // enabling external interrupt
}
Author: Enslaved46
ECE :422
LAB : PWM signal generator with external keyboard interrupt and timer interrupt
*/
#include <18f4455.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //No Power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES NOLVP //No Low-Voltage ICSP Programming
#FUSES HSPLL // High-Speed Crystal with PLL enabled
#FUSES PLL5 //PLL prescaler set to 5
#FUSES CPUDIV1 //no postscaler
#use delay(clock = 48Mhz, crystal = 20Mhz)
#use RS232(UART1, BAUD=115200, PARITY=N, BITS=8, STOP=1, TIMEOUT = 500)
#define OUTPUT_PIN PIN_A3
#include "kbd_yz.c"
#include <lcd.c>
char key_p;
int key_flag=0;
Int16 TN;
#INT_RDA
void key_board(){
key_p=getc();
key_flag=1;
}
#INT_EXT
void key_pad(){
key_p=kbd_getc();
key_flag=1;
}
#INT_TIMER0
void waveform(){
output_toggle(OUTPUT_PIN);
set_timer0(TN + get_timer0());
}
void enable_board();
void reset();
void enable_keyp();
void main(){
int signal_flag=0;
Int16 temp=0;
Int16 time_us;//=0;
Int16 temp1 ;//=0;
lcd_init();
kbd_init();
printf(lcd_putc,"\f ASHISH KHADKA:\n");
enable_keyp();
//output_low(OUTPUT_PIN);
SETUP_TIMER_0(T0_INTERNAL | T0_DIV_1);
//
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
printf("\r\nEnter time mirco-second: ");
while(true){
if(key_p!=0&&key_flag==1){
disable_interrupts(INT_EXT);
temp1=key_p-'0';
key_flag=0;
switch(key_p){
default :
temp=(temp*10)+temp1;
// printf(" temp = %ld \n",temp);
printf(lcd_putc,"%c",key_p);
delay_us(20);
break;
case '*':
key_p=0;
key_flag=0;
temp=0;
time_us=0;
output_low(OUTPUT_PIN);
printf("Reset performed\n");
lcd_putc('\f');
printf(lcd_putc,"Enter time us: \n");
delay_us(20);
enable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER0);
signal_flag=0;
break;
case '#':
printf(" Entered time in us = %ld ",time_us);
time_us=(temp)/2;
signal_flag=1;
printf(lcd_putc,"\fperiod = %ld us ",temp);
delay_us(20);
TN = 65535 - time_us*12+12;
enable_interrupts(INT_TIMER0);
break;
}
}
reset();
}
}
void enable_board(){
clear_interrupt(INT_RDA); // register/output keep old values, need to be cleared
enable_interrupts(INT_RDA); // these 5 statements may be grouped in a function
}
void enable_keyp(){
// these 5 statements reset interrupt
// key_b=0;
set_tris_D(0x1E);
kbd=0x1E;
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
}
void reset() {
set_tris_D(0x01E); // Set column output, row input
kbd=0x1E; // Set all columns low, all rows high
clear_interrupt(INT_EXT); // register/output keep old values, need to be cleared
enable_interrupts(INT_EXT); // enabling external interrupt
}
No comments:
Post a Comment