In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Tristonaz wrote: Hello, I'm in a microcontroller class and my instructor has agreed to let me use the SX instead of the pic kits here. For my first project i am supposed to modify the ADC program on page 302 of "Programming the SX Microcontroller". The idea is to modify it so that instead of controlling the PWM , port B will be used to output an eight bit binary number to some LED's. The binary number will be higher for greater voltages and smaller for lower voltages. Now I've been playing around with this program for awhile now and no matter what i do I can't get the LED's to reflect the voltage at the output. The Code is commented below, so It should be relatively easy to follow (I hope). i believe it to be a logical error, but I'm still really new to the sx assembly language. I thank you for any help you can give me. Triston *********************Code****************************** include "Setup28.inc" Reset main TRIS equ $0f LVL equ $0d PWMpin equ rb.6 ;Port pin for PWM output IntPer equ 163 org $08 PWMAcc ds 1 ;Counter for PWM org 50h ;Bank 2 variables analog equ $ ;ADC bank port_buff ds 1 adc0 ds 1 ;ADC0 Value adc0_acc ds 1 ;ADC0 Accumulator gb adc0_count ds 1 ;Time Counter org $000 bank analog ;select ADC bank ;**Virtual peripheal for two A/D Converters ************************* ; adc mov w, >>rc ;Read Current state of ADC's not w ;turn inputs to outputs and port_buff,w ;Save new value in buffer mov rc,port_buff ;Refresh charge Discharge lines sb port_buff.4 ;ADC0 above threshold ? incsz adc0_acc ;if so, increment accumulator inc adc0_acc ; and avoid overflow by skipping dec adc0_acc ; the second inc instruction inc adc0_count ; increment the counter jnz :done_adcs ; Continue if not yet done mov adc0, adc0_acc ;Update ADC0 value clr adc0_acc ;Clear ADC0 accumulator :done_adcs mov w, #-IntPer ; Call ISR every 'IntPer' cycles retiw org $100 ;** The Main program *********************************************** main clr rc ;intialize Port C mov !rc, #%10101111 ;Configure Port C I/O pins mov !rb, #%00000000 ;Configure Port B output for LED mode LVL ;Set port C input to CMOS mov !rc,#0 ; CMOS mode TRIS ;Restore MODE direction include "Clr2x.inc" ;Clear all data memory mov !option,#%10011111 ;Enable RTCC interrupt :loop bank analog mov w,adc0 mov rb,w jmp :loop ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=184376 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)