Big favour here. I'm looking for someone to write me a tiny little bit of code using the rest of the code I've got here. It should display the binary equivalent of the state on the 8 LEDS (which is incrimented on a button push). Would be so grateful Thanks. Code: ;**************************************************** ;Software License Agreement ; ;The software supplied herewith by Microchip Technology ;Incorporated (the "Company") is intended and supplied to you, the ;Companys customer, for use solely and exclusively on Microchip ;products. The software is owned by the Company and/or its supplier, ;and is protected under applicable copyright laws. All rights are ;reserved. Any use in violation of the foregoing restrictions may ;subject the user to criminal sanctions under applicable laws, as ;well as to civil liability for the breach of the terms and ;conditions of this license. ; ;**************************************************** ;Filename: counter.asm ;Author: Mary JO ;Date: 1/15/03 ;Version: 1.00 ;Description: ; ; ; This firmware implements a counter that displays its results on the leds ; the counter is toggled by the button ; it was derived from a file provided by Microchip and written by R Condit ;**************************************************** ;**************************************************** ;Instructions On How To Use This Program ;**************************************************** ; Press Switch 1 (SW1) on the PICkit(tm) demonstration board to cycle through ; the 256 LED states. ;**************************************************** list p=12f629 ; list directive to define processor #include <p12f629.inc> ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ; ’__CONFIG’ directive is used to embed configuration word within .asm file. ; The labels following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ; ;****************** VARIABLE DEFINITIONS ******************** ; this reserves a pair of registers starting at register 20 Hex ; cblock 0x20 STATE_LED ; LED state machine counter STATE_DEBOUNCE ; button debounce state machine counter endc ; ;****************** DEFINE STATEMENTS ********************** ; ; input and output definitions #define POT GPIO,2 ; potentiometer (not used in this example) #define SW1 GPIO,3 ; toggle switch ; ; define input/output designation for LEDs (what TRISIO will equal) #define TRIS_D0_D1 B'00001111' ; TRISIO setting for D0 and D1 #define TRIS_D2_D3 B'00101011' ; TRISIO setting for D2 and D3 #define TRIS_D4_D5 B'00011011' ; TRISIO setting for D4 and D5 #define TRIS_D6_D7 B'00111001' ; TRISIO setting for D6 and D7 ; ; define LED state (what GPIO will equal) #define D0_ON B'00010000' ; D0 LED #define D1_ON B'00100000' ; D1 LED #define D2_ON B'00010000' ; D2 LED #define D3_ON B'00000100' ; D3 LED #define D4_ON B'00100000' ; D4 LED #define D5_ON B'00000100' ; D5 LED #define D6_ON B'00000100' ; D6 LED #define D7_ON B'00000010' ; D7 LED ; ;******************** Start of Program ******************** org 0x000 ; processor reset vector goto Initialize ;**************************************************** ; Initialize ; Initialize Special Function Registers ;**************************************************** org 0x005 ; Start of Programm Memory Vector Initialize bsf STATUS,RP0 ; Bank 1 movwf OSCCAL ; update register with factory cal value movlw B'00111111' ; Set all I/O pins as inputs movwf TRISIO movlw B'10000001' ; Weak pullups: disabled movwf OPTION_REG ; TMR0 prescaler: 1:64 (TMR0 will overflow in 10.6ms) clrf INTCON ; disable all interrupts, clear all flags bcf STATUS,RP0 ; Bank 0 clrf GPIO ; clear all outputs clrf TMR0 ; clear Timer 0 clrf STATE_LED ; clear LED state machine counter clrf STATE_DEBOUNCE ; clear debounce state machine counter ;**************************************************** ; Main Loop ; Implements a state machine that lights up the LEDs on the PICkit board ; sequentially as a counter when SW1 is pressed. ;**************************************************** MainLoop clrwdt ; clear Watch Dog Timer [B] CODE FOR HERE!!!!!!1111ONE[/B] ;---------------------------- goto MainLoop ;**************************************************** ; Output routines BitOn0 ; Turns on D0 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D0_D1 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D0_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn1 ; Turns on D1 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D0_D1 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D1_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn2 ; Turns on D2 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D2_D3 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D2_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn3 ; Turns on D3 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D2_D3 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D3_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn4 ; Turns on D4 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D4_D5 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D4_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn5 ; Turns on D5 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D4_D5 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D5_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn6 ; Turns on D6 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D6_D7 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D6_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop BitOn7 ; Turns on D7 LED bsf STATUS, RP0 ; Bank 1 movlw TRIS_D6_D7 ; move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw D7_ON ; move predefined value to GPIO movwf GPIO retlw 0 ; go back to main loop ;**************************************************** ; Button_Press ; Looks for button press and implements a button debounce routine. ;**************************************************** Button_Press ; Note that what follows is equivalent to a case statement in ; a high order language movf STATE_DEBOUNCE, w ; Mask out the high order bits of andlw B'00000011' ; STATE_DEBOUNCE. addwf PCL, f goto Debounce_1 goto Debounce_2 goto Debounce_3 goto Debounce_2 ; Send to second state if noise corrupts debounce state counter. Debounce_1 btfsc SW1 ; Is Switch 1 pushed? retlw 0 ; No, then return incf STATE_DEBOUNCE, f ; Yes, then increment both state machines incf STATE_LED, f ; this increments the main counter retlw 0 Debounce_2 btfss SW1 ; Is Switch 1 released? retlw 0 ; No, then return clrf TMR0 ; Yes, clear Timer0 and Timer0 flag bcf INTCON, T0IF incf STATE_DEBOUNCE, f ; Increment debounce state machine retlw 0 Debounce_3 ; Switch must be high for approximately 10 ms before debounce state machine is re-initialized. btfss INTCON, T0IF ; Has 10.6 ms passed? goto Debounce_3a ; No, then check for switch jitter clrf STATE_DEBOUNCE ; Yes, then re-initialize state machine retlw 0 Debounce_3a btfss SW1 ; Is Switch 1 low again (due to switch jitter)? decf STATE_DEBOUNCE, f ; Yes, then go back to debounce state2 retlw 0 ; No, then return. end ; directive ’end of program’
Sorry, managed to get it myself Code: MainLoop clrwdt ; clear Watch Dog Timer call Button_Press ; incriment state if button is pushed. btfsc STATE_LED, 0 Call BitOn0 Clrf GPIO btfsc STATE_LED, 1 call BitOn1 Clrf GPIO btfsc STATE_LED, 2 call BitOn2 Clrf GPIO btfsc STATE_LED, 3 call BitOn3 Clrf GPIO btfsc STATE_LED, 4 call BitOn4 Clrf GPIO btfsc STATE_LED, 5 call BitOn5 Clrf GPIO btfsc STATE_LED, 6 call BitOn6 Clrf GPIO btfsc STATE_LED, 7 call BitOn7 Clrf GPIO goto MainLoop
For future reference, you're more likely to get a response in the electronics forum for PIC based questions. A few comments about your code though - your code is absolute, but Microchip have tried to get rid of this many years ago and are encouraging code to be written in relocatable format so ensure future compatability. Secondly, your code is prone to banking errors. MPASM includes banking macros (e.g. BANKSEL GPIO) to reduce the chance of errors and increase readability. You can also use return to return from a function instead of retlw. edit: The PICkit1 is pretty old so I guess the framework of this code is probably written by Microchip and you've changed bits?