Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************/
- /* */
- /* main.c -- Project 2 */
- /* */
- /* */
- /************************************************************************/
- /* Author: Matthew Michels & Gunjan Majmudar */
- /* */
- /************************************************************************/
- #include "register.h"
- #include <plib.h>
- #include <stdio.h>
- #include <inttypes.h>
- #include "main.h"
- void __ISR( _CHANGE_NOTICE_VECTOR, ipl4) CNInterrupt(void)
- {
- #define PADSTART 0
- #define PADBIT 1
- #define PADSTOP 2
- uint8_t cMap[4] = {0,0,0,0};
- uint8_t rMap[4] = {1,1,1,1};
- short nums[10] = {0,1,2,3,4,5,6,7,8,9};
- uint8_t i = 0;
- if(!C1 || !C2 || !C3 || !C4)
- {
- if (R1==0 && !C1){
- table[count(i)] << 0;
- }
- else if (R1==0 && !C2){
- table[count(i)] << 1;
- }
- else if (R1==0 && !C3){
- table[count(i)] << 2;
- }
- else if (R1==0 && !C4){
- table[count(i)] << 3;
- }
- else if (R2==0 && !C1){
- table[count(i)] << 4;
- }
- else if (R2==0 && !C2){
- table[count(i)] << 5;
- }
- else if (R2==0 && !C3){
- table[count(i)] << 6;
- }
- else if (R2==0 && !C4){
- table[count(i)] << 7;
- }
- else if (R3==0 && !C1){
- table[count(i)] << 8;
- }
- else if (R3==0 && !C2){
- table[count(i)] << 9;
- }
- IFS1CLR = 0x0001; //Clear interrupt flag status bits
- }
- }
- uint8_t count(uint8_t i)
- {
- if(i < 4)
- i++;
- else
- i=0;
- return i;
- }
- int main() {
- TRISB = 0x000f; /*Enable pins 0,1,2,3 as digital input on PortB and pin
- and pins 4,5,6,7 as digital ouputs on PortB*/
- AD1PCFG = 0xffff; //Enable pins as digital pins
- CNCON = 0x8000; //Enable change notification module
- CNEN = 0x003c; //Enable individual pull up pins CN2,CN3,CN4,CN5
- CNPUE = 0x003c; //Enable weak pull up for pins CN2,CN3,CN4, CN5
- //Read port
- PORTB;
- IPC6SET = 0x100000; //Setting interrupt to priority to 7
- IFS1CLR = 0x0001; //Clear interrupt flag status bits
- IEC1SET = 0x0001; //Enable change notification interrupts
- INTEnableSystemMultiVectoredInt();
- INTEnableInterrupts();
- R1=0;
- R2=0;
- R3=0;
- R4=0;
- /*Display*/
- // display();
- //blink ();
- while(1){
- }
- return 0;
- }
- /**Functions**/
- /*Inputing values for the counter using JC PMOD*/
- void valueJC(uint8_t a) {
- char num = number(a);
- AALedJC = ((num >> 6) & 0b1);
- ABLedJC = ((num >> 5) & 0b01);
- ACLedJC = ((num >> 4) & 0b001);
- ADLedJC = ((num >> 3) & 0b0001);
- AELedJC = ((num >> 2) & 0b00001);
- AFLedJC = ((num >> 1) & 0b000001);
- AGLedJC = ((num & 0000001) & 0b0000001);
- }
- /*Inputing values for the counter using JD PMOD*/
- void valueJD(uint8_t a) {
- char num = number(a);
- AALedJD = ((num >> 6) & 0b1);
- ABLedJD = ((num >> 5) & 0b01);
- ACLedJD = ((num >> 4) & 0b001);
- ADLedJD = ((num >> 3) & 0b0001);
- AELedJD = ((num >> 2) & 0b00001);
- AFLedJD = ((num >> 1) & 0b000001);
- AGLedJD = ((num & 0000001) & 0b0000001);
- }
- /*Inputing a number*/
- char number(uint8_t n) {
- char num;
- switch (n) {
- case 0:
- num = 0b1111110;
- break;
- case 1:
- num = 0b0110000;
- break;
- case 2:
- num = 0b1101101;
- break;
- case 3:
- return 0b1111001;
- break;
- case 4:
- num = 0b0110011;
- break;
- case 5:
- num = 0b1011011;
- break;
- case 6:
- num = 0b1011111;
- break;
- case 7:
- num = 0b1110000;
- break;
- case 8:
- num = 0b1111111;
- break;
- case 9:
- num = 0b1110011;
- break;
- }
- return num;
- }
- /*uint8_tializes the PmodSSDInit*/
- void PmodSSDInit() {
- // Configuring Pmod pins as digital outputs.
- trisGLed = 0;
- trisFLed = 0;
- trisCLed = 0;
- trisDLed = 0;
- R1=1;
- R2=1;
- R3=1;
- R4=0;
- }
- /*Enable Change notification*/
- void changeNotification()
- {
- asm volatile("di"); //Disable all interrupts
- TRISB = 0x000f; /*Enable pins 0,1,2,3 as digital input on PortB and pins
- and pins 4,5,6,7 as digital ouputs on PortB*/
- AD1PCFG = 0xffff; //Enable pins as digital pins
- CNCON = 0x8000; //Enable change notification module
- CNEN = 0x003c; //Enable individual pull up pins CN2,CN3,CN4,CN5
- CNPUE = 0x003c; //Enable weak pull up for pins CN2,CN3,CN4, CN5
- //Read port
- PORTB;
- IPC6SET = 0x1c000; //Setting interrupt to priority to 7
- IFS1CLR = 0x0001; //Clear interrupt flag status bits
- IEC1SET = 0x0001; //Enable change notification interrupts
- asm volatile("ei"); //Re-enabling all interrupts
- }
- /*Displays*/
- void display() {
- int i = 0;
- for (i = 0; i < 100000; i++) {
- CathodeJC = 0;
- valueJC(table[0]);
- delay(100);
- CathodeJC = 1;
- valueJC(table[1]);
- delay(100);
- CathodeJD = 0;
- valueJD(table[2]);
- delay(100);
- CathodeJD = 1;
- valueJD(table[3]);
- delay(100);
- }
- }
- /*blink*/
- void blink() {
- int i;
- for (i = 0; i < 100000; i++) {
- table[3] = table[2] = table[1] = table[0] = 9;
- CathodeJC = 0;
- valueJC(table[0]);
- delay2(199);
- CathodeJC = 1;
- valueJC(table[1]);
- delay2(200);
- CathodeJD = 0;
- valueJD(table[2]);
- delay2(199);
- CathodeJD = 1;
- valueJD(table[3]);
- delay2(200);
- }
- }
- /*delay*/
- void delay2(float a) {
- float i = 0;
- while (i < a) {
- i++;
- }
- }
- void delay(int a) {
- int i;
- for (i = 0; i < a; i++) {
- }
- }
- void clrDisplay() {
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement