mình mới học còn gà đang rất gấp .mong các anh em giúp
đây là main.c
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_ENABLE_PIN PIN_D3
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
#include "key.c"
int8 temp;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
delay_ms(500);
lcd_init();
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"Phim Bam:");
key_init();
while(true)
{
temp = key_loai1();
if(temp != 15)
{
if(temp == 11)
{
lcd_gotoxy(10,1);
lcd_putc(" ");
lcd_gotoxy(10,1);
lcd_putc("*");
}
else if(temp == 12)
{
lcd_gotoxy(10,1);
lcd_putc(" ");
lcd_gotoxy(10,1);
lcd_putc("#");
}
else
{
lcd_gotoxy(10,1);
lcd_putc(" ");
lcd_gotoxy(10,1);
printf(lcd_putc,"%02d", temp);
}
}
}
}
-----------------------------------còn đây là key.c--------------------------------
#include "KEY.h"
#define cot_1 PIN_B0
#define cot_2 PIN_B1
#define cot_3 PIN_B2
#define hang_A PIN_B4
#define hang_B PIN_B5
#define hang_C PIN_B6
#define hang_D PIN_B7
void key_init()
{
set_tris_b(0xF0);
//set cac chan Hang_A-D la input
output_high(hang_A);
output_high(hang_B);
output_high(hang_C);
output_high(hang_D);
//set cac chan cot1-3 la dau output
output_low(cot_1);
output_low(cot_2);
output_low(cot_3);
}
unsigned char key_loai1()
{
output_low(cot_1);
output_high(cot_2);
output_high(cot_3);
if(input(hang_A) == 0)
{
delay_ms(200);
return 1; //phim 1 dc bam
}
if(input(hang_B) == 0)
{
delay_ms(200);
return 4; //phim 4 dc bam
}
if(input(hang_C) == 0)
{
delay_ms(200);
return 7; //phim 7 dc bam
}
if(input(hang_D) == 0)
{
delay_ms(200);
return 11; //phim * dc bam
}
delay_ms(5);
output_high(cot_1);
output_low(cot_2);
output_high(cot_3);
if(input(hang_A) == 0)
{
delay_ms(200);
return 2; //phim 2 dc bam
}
if(input(hang_B) == 0)
{
delay_ms(200);
return 5; //phim 5 dc bam
}
if(input(hang_C) == 0)
{
delay_ms(200);
return 8; //phim 8 dc bam
}
if(input(hang_D) == 0)
{
delay_ms(200);
return 0; //phim 0 dc bam
}
delay_ms(5);
output_high(cot_1);
output_high(cot_2);
output_low(cot_3);
if(input(hang_A) == 0)
{
delay_ms(200);
return 3; //phim 3 dc bam
}
if(input(hang_B) == 0)
{
delay_ms(200);
return 6; //phim 6 dc bam
}
if(input(hang_C) == 0)
{
delay_ms(200);
return 9;
}
if(input(hang_D) == 0)
{
delay_ms(200);
return 12; //phim # dc bam
}
delay_ms(5);
return 15; //khong co phim nao dc bam
}
BÂY GIỜ MÌNH MUỐN NÓ HIỂN THỊ MÀ BẤM CÁC KÝ TỰ LIÊN TIẾP MÀ KÝ TỰ TRƯỚC ĐÓ KHÔNG BỊ XÓA THÌ LÀM NTN NHỈ
đây là main.c
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_ENABLE_PIN PIN_D3
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
#include "key.c"
int8 temp;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
delay_ms(500);
lcd_init();
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"Phim Bam:");
key_init();
while(true)
{
temp = key_loai1();
if(temp != 15)
{
if(temp == 11)
{
lcd_gotoxy(10,1);
lcd_putc(" ");
lcd_gotoxy(10,1);
lcd_putc("*");
}
else if(temp == 12)
{
lcd_gotoxy(10,1);
lcd_putc(" ");
lcd_gotoxy(10,1);
lcd_putc("#");
}
else
{
lcd_gotoxy(10,1);
lcd_putc(" ");
lcd_gotoxy(10,1);
printf(lcd_putc,"%02d", temp);
}
}
}
}
-----------------------------------còn đây là key.c--------------------------------
#include "KEY.h"
#define cot_1 PIN_B0
#define cot_2 PIN_B1
#define cot_3 PIN_B2
#define hang_A PIN_B4
#define hang_B PIN_B5
#define hang_C PIN_B6
#define hang_D PIN_B7
void key_init()
{
set_tris_b(0xF0);
//set cac chan Hang_A-D la input
output_high(hang_A);
output_high(hang_B);
output_high(hang_C);
output_high(hang_D);
//set cac chan cot1-3 la dau output
output_low(cot_1);
output_low(cot_2);
output_low(cot_3);
}
unsigned char key_loai1()
{
output_low(cot_1);
output_high(cot_2);
output_high(cot_3);
if(input(hang_A) == 0)
{
delay_ms(200);
return 1; //phim 1 dc bam
}
if(input(hang_B) == 0)
{
delay_ms(200);
return 4; //phim 4 dc bam
}
if(input(hang_C) == 0)
{
delay_ms(200);
return 7; //phim 7 dc bam
}
if(input(hang_D) == 0)
{
delay_ms(200);
return 11; //phim * dc bam
}
delay_ms(5);
output_high(cot_1);
output_low(cot_2);
output_high(cot_3);
if(input(hang_A) == 0)
{
delay_ms(200);
return 2; //phim 2 dc bam
}
if(input(hang_B) == 0)
{
delay_ms(200);
return 5; //phim 5 dc bam
}
if(input(hang_C) == 0)
{
delay_ms(200);
return 8; //phim 8 dc bam
}
if(input(hang_D) == 0)
{
delay_ms(200);
return 0; //phim 0 dc bam
}
delay_ms(5);
output_high(cot_1);
output_high(cot_2);
output_low(cot_3);
if(input(hang_A) == 0)
{
delay_ms(200);
return 3; //phim 3 dc bam
}
if(input(hang_B) == 0)
{
delay_ms(200);
return 6; //phim 6 dc bam
}
if(input(hang_C) == 0)
{
delay_ms(200);
return 9;
}
if(input(hang_D) == 0)
{
delay_ms(200);
return 12; //phim # dc bam
}
delay_ms(5);
return 15; //khong co phim nao dc bam
}
BÂY GIỜ MÌNH MUỐN NÓ HIỂN THỊ MÀ BẤM CÁC KÝ TỰ LIÊN TIẾP MÀ KÝ TỰ TRƯỚC ĐÓ KHÔNG BỊ XÓA THÌ LÀM NTN NHỈ
Comment