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 */
- int delay(void);
- int maths(int n);
- #define MAXVOLT 5 /*Specified channels range is between 0-5 */
- int ledpositions[6]= {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F}; /*Hex values for 1, 2, 3, 4, 5 LEDS on at one time */
- void main() {
- int voltage = 0;
- int perc = 0;
- /*Enable the LEDS*/
- DDRB= 0xFF;
- DDRJ= 0xFF;
- PTJ= 0x00;
- DDRH= 0x00;
- PORTB = 0x00;
- /*Enable the Analogue to Digital System */
- ATD0CTL2 = 0xC0; /*Turn on analogue to digital and turn on fast flag mode */
- ATD0CTL4 = 0xAB; /*10101011*/
- for(;;) {
- ATD0CTL5 = 0x87; /*Find the value in AN7 */
- while (!(ATD0STAT0)){ /* wait for the A/D conversion to complete */
- voltage = ATD0DR0;
- perc = maths(voltage);
- PORTB = ledpositions[perc];
- delay();
- }
- }
- }
- int delay(void) {
- int z = 0;
- for(; z <= 26470; z++){
- }
- }
- int maths(int n) {
- int result = n/100;
- if(result>MAXVOLT){ /* The reading should be between 1-5, however just in case */
- result = MAXVOLT;
- }
- if(result< 1){ /* The reading should be between 1-5, however just in case */
- result = 1;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement