Advertisement
Felanpro

mipslabwork.c

Feb 27th, 2022
1,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. /* mipslabwork.c
  2.  
  3.    This file written 2015 by F Lundevall
  4.    Updated 2017-04-21 by F Lundevall
  5.  
  6.    This file should be changed by YOU! So you must
  7.    add comment(s) here with your name(s) and date(s):
  8.  
  9.    This file modified 2017-04-31 by Ture Teknolog
  10.  
  11.    For copyright and licensing, see file COPYING */
  12.  
  13. #include <stdint.h>   /* Declarations of uint_32 and the like */
  14. #include <pic32mx.h>  /* Declarations of system-specific addresses etc */
  15. #include "mipslab.h"  /* Declarations for these labs */
  16.  
  17. int mytime = 0x5957;
  18.  
  19. char textstring[] = "text, more text, and even more text!";
  20.  
  21. /* Interrupt Service Routine */
  22. void user_isr( void )
  23. {
  24.   return;
  25. }
  26.  
  27. volatile int* porte = (volatile int*) 0xbf886110; //Port E is used for the LED lights
  28. int n = 0;
  29.  
  30. /* Lab-specific initialization goes here */
  31. void labinit( void )
  32. {
  33.     volatile int* trise = (volatile int*) 0xbf886100; //Tris E is used for configuration output = 0, input = 1 of the LED lights
  34.     *trise &= ~0xf00; //Set bits 0 through 7 to 0 (output)
  35.  
  36.     TRISD |= 0xfe0; //Set bits 5 through 11 to input (1 = input) (1111 1110 0000) = 0xfe0
  37.  
  38.     return;
  39. }
  40.  
  41. /* This function is called repetitively from the main program */
  42. void labwork( void )
  43. {
  44.     int buttonStatus = getbtns();
  45.     int switchNumber = getsw();
  46.     if(buttonStatus == 1) //If button 2 is pressed
  47.     {
  48.         mytime &= 0xff0f;
  49.         mytime = ((switchNumber & 0x0f) << 4) | mytime;
  50.     }
  51.     else if(buttonStatus == 2) //If button 3 is pressed
  52.     {
  53.         mytime &= 0xf0ff;
  54.         mytime = ((switchNumber & 0x0f) << 8) | mytime;
  55.     }
  56.     else if(buttonStatus == 4) //If button 4 is pressed
  57.     {
  58.         mytime &= 0x0fff;
  59.         mytime = ((switchNumber & 0x0f) << 12) | mytime;
  60.     }
  61.     else
  62.         *porte = n; // 1 = ON, 0 = OFF The 8 least significant bits correspond to an LED
  63.  
  64.     delay(1000);
  65.     time2string( textstring, mytime );
  66.     display_string( 3, textstring );
  67.     display_update();
  68.     tick( &mytime );
  69.     display_image(96, icon);
  70.     n += 0x1;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement