Skip to content

Instantly share code, notes, and snippets.

@JHeld07
Created December 16, 2015 19:55
Show Gist options
  • Save JHeld07/798f7c96db0cb970f506 to your computer and use it in GitHub Desktop.
Save JHeld07/798f7c96db0cb970f506 to your computer and use it in GitHub Desktop.
// Challenge 4 Microcontolers Fall 2015 Josh Held
#include <18f4520.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOLVP
#include "../../Library/18f4520ptr.h"
#include "../../Library/Keypad.h"
#include "../../Library/modifiedlcd.h"
int16 press1, press2;
float incoming, outgoing;
//Trasmitter code
#INT_RDA // Interrupt for recieve data Only for USART Receive interupt Triggered by proper USART packet receive
void int_rda_isr(){
incoming=*RCREG;
printf(lcd_putc, "\f Current RPM %2.2f", incoming);
*TXREG=press2;
}
// RCREG = Data Receiver Register
// TXREG = Data Trasmit Register
main(){
lcd_init();
*TRISC-0x80;
TXSTA->TXEN=1; // Tx On
TXSTA->SYNC=0; // Asynch
TXSTA->BRGH=0; // Low Speed
RCSTA->SPEN=1; // Rx On RCSTA is setting up two interupts.
RCSTA->CREN=1; // Rx Cont. on
BAUDCON->BRG16=1; // Setting baud rate based off of table.
*SPBRG=129; // setting the interupt
PIE1->RCIE=1; // Rx Interupt Enable
// If Tx Enable is ON it wont work.
INTCON->GIE=1;
INTCON->PEIE=1;
*TXREG=press2;
//Keypad 2 digit
*TRISB=0xF0;
ADCON1->PCFGx=0x0F;// All Digital
INTCON2->RBPU=0;
while(1){
press1=(int16)KeyPress()-0x30; //Takes the ASCII value from the keypress and removes the hex value.
if(press1<=9 && press1>=0){ // Filters out any value other than 0-9
press2=((press2*10)+press1); // Takes the first press, saves it for use when adding press1 to press2
if(press2>100){ // if the press2 value is greater than 100 reset press2 to 0 value.
press2=0;
}
}
printf(lcd_putc,"\n %lu", press2); //Print Pot voltage, print keypad value.
delay_ms(200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment