Hello, I looked at the code and I couldn't find anything wrong. Situations like these are why I bought an ICE200 emulator. It becomes easy to try lots of little variations in order to find what the one little thing is that is preventing success. Anyway, I reformatted the code to make it a little more readable. Maybe the different format will be interesting as an alternative to 'magic numbers'. I would be interested in finding out why this doesn't work. Alan Probandt Portland, OR ****** code below*** .def temp = r16 ;define register 16 as TEMP .def ADCRESULT = r17 ;define register 17 to hold ADC value .equ volt1 = 0x33 ;1 volt threshold value(51 bits/volt) .equ volt2 = 0x66 ;2 volt threshold value .equ volt3 = 0x99 ;3 volt threshold value .equ volt4 = 0xCC ;4 volt threshold value .equ volt5 = 0xFF ;5 volt threshold value .equ LED5v = 4 ; PortB 4 .equ LED4v = 3 ; PortB 3 .equ LED3v = 2 ; PortB 2 .equ LED2v = 1 ; PortB 1 .equ LED1v = 0 ; PortB 0 .equ LEDon = 0 .equ LEDoff = 1 .org 0x0000 rjmp RESET ;jump to reset over vector space RESET: ldi temp, 0b00011111 ;Value to set port B pins 0,1,2,3,4 out DDRB, temp ;to be outputs, 5 to be ADC input ldi temp, 0b00011111 ;value to turn LEDs on port B pins 0-4 off. out PORTB, temp ;load value to port B ldi temp, (1 << ADLAR) | (0<<MUX2) | (0<<MUX1) | (0<<MUX0) ;0b00100000 ;0x20 ;Value to set ADC to: Vcc reference, out ADMUX, temp ;left adjust result,input to PB5 (AD0) ldi temp, (1 << ADEN) | (1 << ADPS1) | (1<< ADPS0); 0b10000011 ; 0x83 ;Value to set up ADC: set to single mode, out ADCSR, temp ;enable ADC, set ADC prescaler to clk/8, disable ADC interrupt ldi temp, (1 << PUD) ;0x40 ;value to set the PUD bit in the MCUCR to disable out MCUCR, temp ;pullup resistors on i/o pins, and load it to MCUCR rjmp MAIN ;jump to main program MAIN: sbi ADCSR, ADSC ;set flag to start AD conversion sbi 0-31, 0-7 LOOP: sbis ADCSR, ADIF ;test if conversion is done. if done ;skip next line and continue, else loop ;back and test again rjmp LOOP ;repeat until conversion is done cbi ADCSR,ADIF ;clear "conversion complete" flag in ADCRESULT, ADCH ;load ADC result to register ldi temp, (LEDoff << LED5v) | (LEDoff << LED4v) | (LEDoff << LED3v) | (LEDoff << LED2v) | (LEDoff << LED1v) ; 0x1F ;value to turn LEDs off (on port B pins 0-4). out PORTB, temp ;load value to port B cpi ADCRESULT, volt5 ;check if ADC reading is 5 volt or more brsh VOUT5 ;if 5 volts or greater, jump to subroutine to ;turn on LEDs on port B, pins 0-4 cpi ADCRESULT, volt4 ;check if 4 volts or more, if so, turn on LED brsh VOUT4 ;port B pins 0-3 cpi ADCRESULT, volt3 ;check if 3 volts or more, if so, turn on LED brsh VOUT3 ;on port B pins 0-2 cpi ADCRESULT, volt2 ;check if 2 volts or greater, if so, turn on LED brsh VOUT2 ;on port B pins 0-1 cpi ADCRESULT, volt1 ;check if 1 volt or greater, if so, turn on LED brsh VOUT1 ;on port B pin 0 ldi temp,(LEDoff << LED5v) | (LEDoff << LED4v) | (LEDoff << LED3v) | (LEDoff << LED2v) | (LEDoff << LED1v) ;0x1F ;all above tests are false, turn off all LEDS rjmp MAIN ;return for another sample VOUT5: ldi temp, (LEDon << LED5v) | (LEDon << LED4v) | (LEDon << LED3v) | (LEDon << LED2v) | (LEDon << LED1v) ;0x00 ;value to turn on all LEDs out PORTB, temp ;turn on LEDs rjmp MAIN ;return for another sample VOUT4: ldi temp, (LEDoff << LED5v) | (LEDon << LED4v) | (LEDon << LED3v) | (LEDon << LED2v) | (LEDon << LED1v) ;0x10 ;value to turn on LEDs on port B 0-3 out PORTB, temp ;turn on LEDs rjmp MAIN ;return for another sample VOUT3: ldi temp,(LEDoff << LED5v) | (LEDoff << LED4v) | (LEDon << LED3v) | (LEDon << LED2v) | (LEDon << LED1v) ; 0x18 ;value to turn on LEDs on port B 0-2 out PORTB, temp ;turn on LEDs rjmp MAIN ;return for another sample VOUT2: ldi temp, (LEDoff << LED5v) | (LEDoff << LED4v) | (LEDoff << LED3v) | (LEDon << LED2v) | (LEDon << LED1v) ; 0x1C ;value to turn on LEDs on port B 0-1 out PORTB, temp ;turn on LEDs rjmp MAIN ;return for another sample VOUT1: ldi temp, (LEDoff << LED5v) | (LEDoff << LED4v) | (LEDoff << LED3v) | (LEDoff << LED2v) | (LEDon << LED1v) ;0x1E ;value to turn on LEDs on port B 0 out PORTB, temp ;turn on LEDs rjmp MAIN ;return for another sample
Message
Re: Why won't this work?
2004-10-01 by alan_probandt
Attachments
- No local attachments were found for this message.