Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <hidef.h> /* common defines and macros */
- #include "derivative.h" /* derivative-specific definitions */
- #include <stdio.h>
- void delay(void);
- int maths(int n);
- #define MAXVOLT 5 /*Specified channels range is between 0-5 */
- #define DIVISOR 48 /*Specified channels range is between 0-5 */
- int sevensegnumbers[10]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; /*Hex values for 1, 2, 3, 4, 5 LEDS on at one time */
- int windows[4] = {0x0E, 0x0D, 0x0B, 0x07};
- void main() {
- int voltage = 0;
- int perc = 0;
- /*Enable the LEDS*/
- DDRB= 0xFF;
- DDRJ= 0xFF;
- DDRP= 0xFF;
- PTJ= 0x00;
- DDRH= 0x00;
- PTP = windows[1]; /*Decimal Point */
- PORTB = 0x80;
- delay();
- delay();
- /*Enable the Analogue to Digital System */
- ATD0CTL2 = 0xC0; /*1100 0000 Turn on analogue to digital and turn on fast flag mode */
- ATD0CTL4 = 0xBB; /*10111011*/
- for(;;) {
- ATD0CTL5 = 0x87; /*Find the value in AN7 */
- while (!(ATD0STAT0)){ /* wait for the A/D conversion to complete */
- voltage = ATD0DR0;
- delay();
- perc = maths(voltage);
- delay();
- }
- }
- }
- void delay() {
- int z = 0;
- for(z; z <= 23470; z++){
- }
- }
- int maths(int n) {
- int result = (n*10/DIVISOR); /*Times by 10 to avoid floating point*/
- int win1 = result/10;
- int win2 = 0;
- win2 = ((win1%10));
- PTP = windows[0]; /*Decimal Point */
- PORTB = sevensegnumbers[win1];
- delay();
- PTP = windows[2]; /*Decimal Point */
- PORTB = sevensegnumbers[win2];
- delay();
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement