0% found this document useful (0 votes)
4 views

Doc1

The document contains multiple code snippets for microcontroller programming, specifically using the PIC16F887. Each section includes different configurations, pin definitions, and functions for controlling a digital clock with a 7-segment display and LCD. The code demonstrates the use of interrupts, timers, and input handling for a digital clock application.

Uploaded by

nvdat19032004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Doc1

The document contains multiple code snippets for microcontroller programming, specifically using the PIC16F887. Each section includes different configurations, pin definitions, and functions for controlling a digital clock with a 7-segment display and LCD. The code demonstrates the use of interrupts, timers, and input handling for a digital clock application.

Uploaded by

nvdat19032004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Đề 1 đề 2 đề 3 đề 4 đề 5

#include <main.h> #include <16f887.h> #include <16f887.h> #include <16F887.h> #include <16F887.h>
#fuses HS #fuses hs,noprotect,nowdt,put #fuses HS #fuses HS
#use delay(clock=20m) #use delay(clock=20m) #use delay(crystal=20000000) #use delay(crystal=20000000)
#define but_START PIN_B6 #define LCD_ENABLE_PIN unsigned int16
#define but_stop PIN_B7 PIN_D2 maphim[16]={0xc0,0xf9,0xa4, unsigned int8 Code7Seg[] = {0xC0, #define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_D0 0xb0,0x99,0x92, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, #define LCD_RS_PIN PIN_C0
#define ctr_chuc PIN_D0 #define LCD_RW_PIN PIN_D1 0x82,0xf8,0x80,0x90,0x88,0x8 0xF8, 0x80, 0x90}; #define LCD_RW_PIN PIN_C1
#define ctr_dvi PIN_D1 #define LCD_DATA4 PIN_D4 3, unsigned int8 count = 0, chuc, dvi; #define LCD_DATA4 PIN_C4
#define LCD_DATA5 PIN_D5 0xc6,0xa1,0x86,0x8e}; int1 counting = 0; #define LCD_DATA5 PIN_C5
#define LCD_DATA6 PIN_D6 unsigned int8 mq; #define LCD_DATA6 PIN_C6
const unsigned int8 #define LCD_DATA7 PIN_D7 void phim44() #int_TIMER1 #define LCD_DATA7 PIN_C7
Code7Seg[] = {0xC0, 0xF9, #include <LCD.C> { void TIMER1_isr() {
0xA4, 0xB0, 0x99, 0x92, unsigned int8 if (counting) { #include <lcd.c>
0x82, 0xF8, 0x80, 0x90}; unsigned int8 gio = 0, phut = 0, giay mt[4]={0xfe,0xfd,0xfb,0xf7}; count++;
= 0; unsigned int8 cot=0; if (count > 99) count = 0; unsigned int16 count = 0;
int1 clock_running = 0; for(cot=0;cot<4;cot++) } unsigned int8 timer_overflow_count = 0;
void Display_2digits(unsigned { set_timer1(3036);
int16 x) void display_time() output_d(mt[cot]); } #INT_TIMER0
{ { while(input(pin_d7)==0) void timer0_isr() {
unsigned char chuc, dvi; lcd_gotoxy(1, 2); {mq=cot*4+0;} void main() { timer_overflow_count++;
chuc = x / 10; printf(lcd_putc, "%02u-%02u- while(input(pin_d6)==0) set_tris_b(0x00); if (timer_overflow_count >= 4) {
dvi = x % 10; %02u", gio, phut, giay); {mq=cot*4+1;} set_tris_c(0x00); count++;
} while(input(pin_d5)==0) set_tris_d(0b00000011); if (count > 999) {
output_c(Code7Seg[chuc]); {mq=cot*4+2;} count = 0;
output_bit(ctr_chuc, 0); void main() while(input(pin_d4)==0) setup_timer_1(T1_INTERNAL | }
delay_ms(5); { {mq=cot*4+3;} T1_DIV_BY_8); timer_overflow_count = 0;
output_bit(ctr_chuc, 1); set_tris_d(0x00); } set_timer1(3036); }
lcd_init(); } }
void main() enable_interrupts(INT_TIMER1);
output_c(Code7Seg[dvi]); while(true) { enable_interrupts(GLOBAL); void Display_Lcd(unsigned int16 x)
output_bit(ctr_dvi, 0); { set_tris_c(0xc0); {
delay_ms(5); if(input(PIN_B6) == 0) output_c(0xff); while (true) { unsigned int8 tram, chuc, dvi;
output_bit(ctr_dvi, 1); { set_tris_d(0xf0); if (!input(pin_d0)) {
} delay_ms(20); while(true) counting = 1; tram = x / 100;
if(input(PIN_B6) == 0) { } chuc = (x % 100) / 10;
void main() { phim44(); if (!input(pin_d1)) { dvi = (x % 100) % 10;
{ lcd_gotoxy(1, 1); output_c(maphim[mq]); counting = 0;
unsigned int16 count = 0; lcd_putc("DIGITAL } } lcd_putc(tram + 0x30);
int8 counting = 0; CLOCK"); } lcd_putc(chuc + 0x30);
clock_running = 1; chuc = count / 10; lcd_putc(dvi + 0x30);
set_tris_c(0x00); } dvi = count % 10; }
set_tris_d(0x00); while(input(PIN_B6) == 0);
set_tris_b(0xFF); } output_b(Code7Seg[chuc]); void main()
port_b_pullups(0xFF); output_c(Code7Seg[dvi]); {
if(input(PIN_B7) == 0) lcd_init();
while(TRUE) { delay_ms(10); lcd_gotoxy(1,1);
{ delay_ms(20); } lcd_putc("VI DIEU KHIEN");
if(input(PIN_B7) == 0) } lcd_gotoxy(1,2);
if(!input(but_START) { lcd_putc("LAP TRINH TIMER 0");
&& !counting) clock_running = 0; lcd_gotoxy(1,3);
{ } lcd_putc("COUNT=");
counting = 1; while(input(PIN_B7) == 0); set_tris_c(0x00);
delay_ms(200); }
}
if(clock_running) setup_timer_0(RTCC_INTERNAL |
{ RTCC_DIV_256);
if(!input(but_stop) && delay_ms(1000); set_timer0(0);
counting) giay++; enable_interrupts(INT_TIMER0);
{ if(giay >= 60) enable_interrupts(GLOBAL);
counting = 0; {
delay_ms(200); giay = 0; while(true)
} phut++; {
if(counting) if(phut >= 60) lcd_gotoxy(9,3);
{ { Display_Lcd(count);
count++; phut = 0; }
gio++; }
if(count >= 100) if(gio >= 24)
{ {
count = 0; gio = 0;
} }
} }
}
display_time();
for(int i = 0; i < 50; i++) }
{ }
Display_2digits(count); }
}
}
}
Đề 1 đề 2 đề 3 đề 4 đề 5

You might also like