Created
February 2, 2020 11:20
-
-
Save gresan-gits/d70eb1b41d2342723b09c5f5672a1340 to your computer and use it in GitHub Desktop.
CCS C INT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ext.h> | |
#define LED_BAO PIN_D0 | |
#define LED_NGAT PIN_D1 | |
#INT_EXT //chi thi khai bao ngat(Chuong trinh se thuc hien ham ngay sau chi thi) | |
void ngatngoai0_isr(VOID) //ham thuch hien khi co ngat | |
{ | |
fprintf (DEBUG_PORT, "\r\nBat dau thuc hien ham trong ngat"); | |
output_toggle (LED_NGAT); | |
for (INT i = 0; i < 10; i++) | |
{ | |
fprintf (DEBUG_PORT, "\r\ni = %u",i); | |
delay_ms (200); | |
} | |
fprintf (DEBUG_PORT, "\r\nKet thuc thuc hien ham trong ngat"); | |
} | |
#INT_EXT1 //chi thi khai bao ngat(Chuong trinh se thuc hien ham ngay sau chi thi) | |
void ngatngoai1_isr(VOID) //ham thuch hien khi co ngat ngoai 1 | |
{ | |
fprintf (DEBUG_PORT, "\r\nXay ra ngat ngoai 1"); | |
} | |
int8 so_lan; | |
void main() | |
{ | |
enable_interrupts (INT_EXT); //Cho phep ngat ngoai 0 | |
enable_interrupts (INT_EXT1); //Cho phep ngat ngoai 1 | |
enable_interrupts (INT_EXT_H2L); //ngat khi co su thay doi trang thau tu H (muc cao) xuong L (muc thap) | |
enable_interrupts (INT_EXT1_H2L); //ngat khi co su thay doi trang thau tu H (muc cao) xuong L (muc thap) | |
enable_interrupts (GLOBAL); //Cho phep ngat toan cuc | |
fprintf (DEBUG_PORT, "\r\nChay WHILE (true) "); | |
so_lan = 0; | |
WHILE (TRUE) | |
{ | |
so_lan++; | |
if(so_lan>255) | |
{ | |
so_lan=0; | |
} | |
output_toggle (LED_BAO); | |
delay_ms (100); | |
IF (so_lan == 100) | |
{ | |
disable_interrupts (INT_EXT); //Khong cho phep ngat ngoai 0 | |
fprintf (DEBUG_PORT, "\r\nTat cho phep ngat ngoai 0 "); | |
} | |
IF (so_lan == 200) | |
{ | |
enable_interrupts (INT_EXT); //Khong cho phep ngat ngoai 0 | |
fprintf (DEBUG_PORT, "\r\nBat cho phep ngat ngoai 0 "); | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <18F4520.h> | |
#FUSES NOWDT //No Watch Dog Timer | |
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale | |
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) | |
#FUSES NOBROWNOUT //No brownout reset | |
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O | |
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) | |
#use delay(clock=20000000) | |
#use rs232(UART1,baud=9600,parity=N,bits=8,stream=DEBUG_PORT,errors)//Khai bao su dung uart cung | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment