Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <hidef.h> /* common defines and macros */
  2. #include "derivative.h" /* derivative-specific definitions */
  3. int delay(void);
  4. int maths(int n);
  5.  
  6. #define MAXVOLT 5 /*Specified channels range is between 0-5 */
  7.  
  8. int ledpositions[6]= {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F}; /*Hex values for 1, 2, 3, 4, 5 LEDS on at one time */
  9.  
  10. void main() {
  11. int voltage = 0;
  12. int perc = 0;
  13. /*Enable the LEDS*/
  14. DDRB= 0xFF;
  15. DDRJ= 0xFF;
  16. PTJ= 0x00;
  17. DDRH= 0x00;
  18. PORTB = 0x00;
  19.  
  20.  
  21. /*Enable the Analogue to Digital System */
  22. ATD0CTL2 = 0xC0; /*Turn on analogue to digital and turn on fast flag mode */
  23. ATD0CTL4 = 0xAB; /*10101011*/
  24.  
  25.  
  26. for(;;) {
  27. ATD0CTL5 = 0x87; /*Find the value in AN7 */
  28. while (!(ATD0STAT0)){ /* wait for the A/D conversion to complete */
  29. voltage = ATD0DR0;
  30. perc = maths(voltage);
  31. PORTB = ledpositions[perc];
  32. delay();
  33. }
  34. }
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41. int delay(void) {
  42. int z = 0;
  43. for(; z <= 26470; z++){
  44.  
  45. }
  46. }
  47.  
  48.  
  49. int maths(int n) {
  50. int result = n/100;
  51. if(result>MAXVOLT){ /* The reading should be between 1-5, however just in case */
  52. result = MAXVOLT;
  53. }
  54. if(result< 1){ /* The reading should be between 1-5, however just in case */
  55. result = 1;
  56. }
  57.  
  58. return result;
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement