Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <hidef.h> /* common defines and macros */
  2. #include "derivative.h" /* derivative-specific definitions */
  3. #include <stdio.h>
  4. void delay(void);
  5. int maths(int n);
  6.  
  7. #define MAXVOLT 5 /*Specified channels range is between 0-5 */
  8. #define DIVISOR 48 /*Specified channels range is between 0-5 */
  9. 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 */
  10. int windows[4] = {0x0E, 0x0D, 0x0B, 0x07};
  11.  
  12. void main() {
  13. int voltage = 0;
  14. int perc = 0;
  15.  
  16. /*Enable the LEDS*/
  17. DDRB= 0xFF;
  18. DDRJ= 0xFF;
  19. DDRP= 0xFF;
  20. PTJ= 0x00;
  21. DDRH= 0x00;
  22. PTP = windows[1]; /*Decimal Point */
  23. PORTB = 0x80;
  24. delay();
  25. delay();
  26.  
  27.  
  28. /*Enable the Analogue to Digital System */
  29. ATD0CTL2 = 0xC0; /*1100 0000 Turn on analogue to digital and turn on fast flag mode */
  30. ATD0CTL4 = 0xBB; /*10111011*/
  31.  
  32.  
  33. for(;;) {
  34. ATD0CTL5 = 0x87; /*Find the value in AN7 */
  35. while (!(ATD0STAT0)){ /* wait for the A/D conversion to complete */
  36. voltage = ATD0DR0;
  37. delay();
  38. perc = maths(voltage);
  39. delay();
  40. }
  41. }
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48. void delay() {
  49. int z = 0;
  50. for(z; z <= 23470; z++){
  51. }
  52. }
  53.  
  54. int maths(int n) {
  55. int result = (n*10/DIVISOR); /*Times by 10 to avoid floating point*/
  56. int win1 = result/10;
  57. int win2 = 0;
  58. win2 = ((win1%10));
  59. PTP = windows[0]; /*Decimal Point */
  60. PORTB = sevensegnumbers[win1];
  61. delay();
  62. PTP = windows[2]; /*Decimal Point */
  63. PORTB = sevensegnumbers[win2];
  64. delay();
  65. return result;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement