Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.40 KB | None | 0 0
  1. /************************************************************************/
  2. /*                                                                      */
  3. /*  main.c  -- Project 2                                                */
  4. /*                                                                      */
  5. /*                                                                      */
  6. /************************************************************************/
  7. /*  Author:     Matthew Michels & Gunjan Majmudar                       */
  8. /*                                                                      */
  9. /************************************************************************/
  10.  
  11. #include "register.h"
  12. #include <plib.h>
  13. #include <stdio.h>
  14. #include <inttypes.h>
  15. #include "main.h"
  16.  
  17. void __ISR( _CHANGE_NOTICE_VECTOR, ipl4) CNInterrupt(void)
  18. {
  19.  
  20. #define PADSTART    0
  21. #define PADBIT      1
  22. #define PADSTOP     2
  23.  
  24.     uint8_t cMap[4] = {0,0,0,0};
  25.     uint8_t rMap[4] = {1,1,1,1};
  26.  
  27.     short nums[10] = {0,1,2,3,4,5,6,7,8,9};
  28.  
  29.     uint8_t i = 0;
  30.  
  31.  
  32.     if(!C1 || !C2 || !C3 || !C4)
  33.     {
  34.         if (R1==0 && !C1){
  35.             table[count(i)] << 0;
  36.         }
  37.         else if (R1==0 && !C2){
  38.             table[count(i)] << 1;
  39.         }  
  40.         else if (R1==0 && !C3){
  41.             table[count(i)] << 2;
  42.         }
  43.         else if (R1==0 && !C4){
  44.             table[count(i)] << 3;
  45.         }
  46.         else if (R2==0 && !C1){
  47.             table[count(i)] << 4;
  48.         }
  49.         else if (R2==0 && !C2){
  50.             table[count(i)] << 5;
  51.         }  
  52.         else if (R2==0 && !C3){
  53.             table[count(i)] << 6;
  54.         }
  55.         else if (R2==0 && !C4){
  56.             table[count(i)] << 7;
  57.         }
  58.         else if (R3==0 && !C1){
  59.             table[count(i)] << 8;
  60.         }
  61.         else if (R3==0 && !C2){
  62.             table[count(i)] << 9;
  63.         }
  64.  
  65.         IFS1CLR = 0x0001;       //Clear interrupt flag status bits
  66.     }
  67.  
  68.  
  69. }
  70.  
  71. uint8_t count(uint8_t i)
  72. {
  73.     if(i < 4)
  74.         i++;
  75.     else
  76.         i=0;
  77.  
  78.     return i;
  79. }
  80.  
  81.  
  82.  
  83.  
  84. int main() {
  85.  
  86.     TRISB = 0x000f;    /*Enable pins 0,1,2,3 as digital input on PortB and pin
  87.                        and pins 4,5,6,7 as digital ouputs on PortB*/
  88.  
  89.     AD1PCFG = 0xffff;   //Enable pins as digital pins
  90.     CNCON = 0x8000;     //Enable change notification module
  91.     CNEN = 0x003c;      //Enable individual pull up pins CN2,CN3,CN4,CN5
  92.     CNPUE = 0x003c;     //Enable weak pull up for  pins CN2,CN3,CN4, CN5
  93.  
  94.     //Read port
  95.     PORTB;
  96.  
  97.     IPC6SET = 0x100000;     //Setting interrupt to priority to 7
  98.     IFS1CLR = 0x0001;       //Clear interrupt flag status bits
  99.     IEC1SET = 0x0001;       //Enable change notification interrupts
  100.     INTEnableSystemMultiVectoredInt();
  101.     INTEnableInterrupts();
  102.  
  103.     R1=0;
  104.     R2=0;
  105.     R3=0;
  106.     R4=0;
  107.  
  108.  
  109.  
  110.     /*Display*/
  111.     //  display();
  112.  
  113.     //blink ();
  114.     while(1){
  115.     }
  116.  
  117.  
  118.     return 0;
  119.  
  120. }
  121.  
  122. /**Functions**/
  123.  
  124. /*Inputing values for the counter using JC PMOD*/
  125. void valueJC(uint8_t a) {
  126.     char num = number(a);
  127.  
  128.     AALedJC = ((num >> 6) & 0b1);
  129.     ABLedJC = ((num >> 5) & 0b01);
  130.     ACLedJC = ((num >> 4) & 0b001);
  131.     ADLedJC = ((num >> 3) & 0b0001);
  132.     AELedJC = ((num >> 2) & 0b00001);
  133.     AFLedJC = ((num >> 1) & 0b000001);
  134.     AGLedJC = ((num & 0000001) & 0b0000001);
  135.  
  136. }
  137.  
  138. /*Inputing values for the counter using JD PMOD*/
  139. void valueJD(uint8_t a) {
  140.     char num = number(a);
  141.  
  142.     AALedJD = ((num >> 6) & 0b1);
  143.     ABLedJD = ((num >> 5) & 0b01);
  144.     ACLedJD = ((num >> 4) & 0b001);
  145.     ADLedJD = ((num >> 3) & 0b0001);
  146.     AELedJD = ((num >> 2) & 0b00001);
  147.     AFLedJD = ((num >> 1) & 0b000001);
  148.     AGLedJD = ((num & 0000001) & 0b0000001);
  149. }
  150.  
  151. /*Inputing a number*/
  152. char number(uint8_t n) {
  153.     char num;
  154.     switch (n) {
  155.     case 0:
  156.         num = 0b1111110;
  157.         break;
  158.     case 1:
  159.         num = 0b0110000;
  160.         break;
  161.     case 2:
  162.         num = 0b1101101;
  163.         break;
  164.     case 3:
  165.         return 0b1111001;
  166.         break;
  167.     case 4:
  168.         num = 0b0110011;
  169.         break;
  170.     case 5:
  171.         num = 0b1011011;
  172.         break;
  173.     case 6:
  174.         num = 0b1011111;
  175.         break;
  176.     case 7:
  177.         num = 0b1110000;
  178.         break;
  179.     case 8:
  180.         num = 0b1111111;
  181.         break;
  182.     case 9:
  183.         num = 0b1110011;
  184.         break;
  185.     }
  186.     return num;
  187. }
  188.  
  189. /*uint8_tializes the PmodSSDInit*/
  190. void PmodSSDInit() {
  191.     // Configuring Pmod pins as digital outputs.
  192.  
  193.     trisGLed = 0;
  194.     trisFLed = 0;
  195.     trisCLed = 0;
  196.     trisDLed = 0;
  197.  
  198.     R1=1;
  199.     R2=1;
  200.     R3=1;
  201.     R4=0;
  202.  
  203. }
  204.  
  205.  
  206.  
  207. /*Enable Change notification*/
  208. void changeNotification()
  209. {
  210.  
  211.     asm volatile("di"); //Disable all interrupts
  212.  
  213.     TRISB = 0x000f;    /*Enable pins 0,1,2,3 as digital input on PortB and pins
  214.                        and pins 4,5,6,7 as digital ouputs on PortB*/
  215.  
  216.     AD1PCFG = 0xffff;   //Enable pins as digital pins
  217.     CNCON = 0x8000;     //Enable change notification module
  218.     CNEN = 0x003c;      //Enable individual pull up pins CN2,CN3,CN4,CN5
  219.     CNPUE = 0x003c;     //Enable weak pull up for  pins CN2,CN3,CN4, CN5
  220.  
  221.     //Read port
  222.     PORTB;
  223.  
  224.     IPC6SET = 0x1c000;      //Setting interrupt to priority to 7
  225.     IFS1CLR = 0x0001;       //Clear interrupt flag status bits
  226.     IEC1SET = 0x0001;       //Enable change notification interrupts
  227.  
  228.     asm volatile("ei");     //Re-enabling all interrupts
  229. }
  230.  
  231.  
  232.  
  233.  
  234. /*Displays*/
  235. void display() {
  236.     int i = 0;
  237.  
  238.     for (i = 0; i < 100000; i++) {
  239.  
  240.  
  241.         CathodeJC = 0;
  242.         valueJC(table[0]);
  243.         delay(100);
  244.  
  245.         CathodeJC = 1;
  246.         valueJC(table[1]);
  247.         delay(100);
  248.  
  249.         CathodeJD = 0;
  250.         valueJD(table[2]);
  251.         delay(100);
  252.  
  253.         CathodeJD = 1;
  254.         valueJD(table[3]);
  255.         delay(100);
  256.  
  257.     }
  258. }
  259.  
  260.  
  261. /*blink*/
  262. void blink() {
  263.     int i;
  264.     for (i = 0; i < 100000; i++) {
  265.         table[3] = table[2] = table[1] = table[0] = 9;
  266.  
  267.         CathodeJC = 0;
  268.         valueJC(table[0]);
  269.         delay2(199);
  270.  
  271.         CathodeJC = 1;
  272.         valueJC(table[1]);
  273.         delay2(200);
  274.  
  275.         CathodeJD = 0;
  276.         valueJD(table[2]);
  277.         delay2(199);
  278.  
  279.         CathodeJD = 1;
  280.         valueJD(table[3]);
  281.         delay2(200);
  282.     }
  283. }
  284.  
  285.  
  286. /*delay*/
  287.  
  288. void delay2(float a) {
  289.     float i = 0;
  290.     while (i < a) {
  291.         i++;
  292.     }
  293. }
  294.  
  295. void delay(int a) {
  296.     int i;
  297.     for (i = 0; i < a; i++) {
  298.     }
  299. }
  300.  
  301. void clrDisplay() {
  302.  
  303.     display();
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement