Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <C8051F340.h>
  2.  
  3. void configTimer (void);
  4. void configInterruption (void);
  5. void reloadTimer (void);
  6. void switch_0 (void) __interrupt 0;
  7. void switch_1(void) __interrupt 2;
  8. void RSI_Timer0 (void) __interrupt 1;
  9.  
  10. char overflowCounter = 0;
  11. char threshold = 128;
  12.  
  13. int main (void) {
  14.  
  15. configTimer();
  16.  
  17. configInterruption();
  18.  
  19. TR0 = 1;
  20.  
  21. while (1) {
  22.  
  23. if (overflowCounter<=threshold) {
  24. P2_2=1;
  25. } else {
  26. P2_2=0;
  27. }
  28. }
  29. }
  30.  
  31. void RSI_Timer0 (void) __interrupt 1 {
  32. overflowCounter++;
  33. }
  34.  
  35. void switch_0 (void) __interrupt 0 {
  36. threshold++;
  37. }
  38.  
  39. void switch_1 (void) __interrupt 2 {
  40. threshold--;
  41. }
  42.  
  43. void configTimer (void) {
  44. P2MDOUT = 0x0C;
  45. P0SKIP = 0xFF;
  46. P1SKIP = 0xFF;
  47. XBR1 = 0X70;
  48. OSCICN = 0x83;
  49. PCA0MD &= 0xBF;
  50. PCA0MD = 0x00;
  51.  
  52. reloadTimer ();
  53. TMOD=0x01;
  54. }
  55.  
  56. void configInterruption (void) {
  57. IE=0x87;
  58. IT01CF=0xC1;
  59. }
  60.  
  61. void reloadTimer (void) {
  62. TH0=0xFC;
  63. TL0=0xFC;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement