Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Anyone know Assembler language?
Page 1 of 3 | |||||
Author | Message | ||||
lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I want to port across something I only have in assembler to a Pico But as most of you know I'm hopeless with code However I'm going to give it a go If anyone knows how to read assembler could you "PLEASE" tell me what the following subroutines do, as in how the get the values and where from CHECKTHR 'This check the threshold but where does it get the threshold from THRSET 'sets the threshold "somehow" DONETHR 'done setting the threshold? LEDBAR 'How/Where does is get the dbm values from? TETRA4S 'I think contains 4 second timer? MAIN 'Start A/D convert? how does it assign the (RSSI)dbm figure? CONV0 'I think this reads the analog input and assigns the RSSI(dbm) value but How? Once I understand how those work, I should be able to do the rest LIST P=16F818, F=INHX8M #include <p16f818.inc> __CONFIG _WDT_OFF & _PWRTE_OFF & _INTRC_IO & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_ENABLE_OFF & _DEBUG_OFF & _CCP1_RB2 & _CP_OFF ; Equates RESET_V EQU 0x00 ; Address of RESET Vector OSC_FREQ EQU D'8000000' ; Internal Oscillator Frequency is 8 MHz ; Registers FLAGS EQU 0x20 ; Various flags THRLVL EQU 0x21 ; Threshold level set via UI MAXH EQU 0x22 ; LEVEL MAX HOLD value to be shown on LED bar TEMPBAR EQU 0x23 ; Pattern on LED bar if it's blanked (BRT) TEMPTHR EQU 0x24 ; Used in threshold set routine BRITE EQU 0x25 ; LED Brightness T4S EQU 0x26 ; Tetra 4s timing I2CDELAY EQU 0x27 ; Used for I2C timing I2CBUF EQU 0x28 ; Used for I2C data I2CCNT EQU 0x29 ; Used for I2C bitbanger DB2 EQU 0x30 ; Stealth byte for prescaler (0x50-0x5F) TEMPW EQU 0x40 ; Context saving for interrupts TEMPSTATUS EQU 0x41 ; in all banks ; Defines #define LEDS PORTB ; 8 LED bar RB0-3 GRN, RB4,5 ORG RB6,7 RED #define RSSI PORTA, 0 ; A/D input from AD8307 #define ALARM PORTA, 1 ; Threshold Alarm Output #define THR PORTA, 3 ; Alarm threshhold button input #define BRT PORTA, 4 ; LED brightness button input #define SCL PORTA, 6 #define SDA PORTA, 7 ; I2C bus outputs #define BLANKBAR FLAGS, 0 ; 1: blanked (BRT) #define BRTBTN FLAGS, 1 ; 1: BRT Button Pressed #define NITE FLAGS, 3 ; 1: lowest brightness #define DIM FLAGS, 4 ; 1: low brightness #define DAY FLAGS, 5 ; 1: mid brightness #define FULL FLAGS, 6 ; 1: max brightness ORG 0 GOTO START ORG 4 ; Timer0 Interrupt Handler BCF INTCON , TMR0IF ; Clear TMR0 interrupt BCF INTCON , GIE ; Disable global interrupts MOVWF TEMPW ; Copy W to a Temporary Register (all banks) SWAPF STATUS , W ; Swap STATUS nibbles and place into W register MOVWF TEMPSTATUS ; Save STATUS to a Temporary register (DS31008a) CALL BARBRITE ; BRT Button test CALL THRSET ; Threshold Setting Routine MOVLW B'00000001' XORWF FLAGS , 1 ; XOR BLANKBAR BTFSC BLANKBAR ; Test if clear GOTO BLANKLEDS ; Set, blank leds MOVFW BRITE ; Fetch LED brightness SUBLW 0xFF ; Subtract BRITE from 0xFF MOVWF TMR0 ; And load Timer0 MOVFW TEMPBAR ; Fetch LED pattern MOVWF LEDS ; Write to LEDs GOTO ENDINT BLANKLEDS MOVFW BRITE ; Fetch LED brightness MOVWF TMR0 ; And load Timer0 CLRF LEDS ; Switch off LEDs CALL TETRA4S ; Check if 4s have elapsed, if so write pattern to TEMPBAR. ENDINT SWAPF TEMPSTATUS , W ; Swap original STATUS register value MOVWF STATUS ; Restore STATUS register from W SWAPF TEMPW , F ; Swap W_Temp nibbles and return value to W_Temp SWAPF TEMPW , W ; Swap W_Temp to W to restore original W (DS31008a) BSF INTCON , GIE ; Re-enable global interrupts RETFIE START ; Init stuff CLRF STATUS ; Do initialization, Select bank 0 CLRF INTCON BSF INTCON , GIE ; Enable GIE BSF INTCON , TMR0IE ; Enable Timer0 Interrupt CLRF PCLATH ; Keep in lower 2KByte CLRF CCP1CON MOVLW B'00111111' BANKSEL TRISA MOVWF TRISA ; RA7,6 Outputs, 5-0 Inputs CLRF TRISB ; RB7-0 Outputs MOVLW B'00000110' ; Timer0, prescaler 1:128 MOVWF OPTION_REG MOVLW B'01110000' ; 8 MHz clock MOVWF OSCCON MOVLW B'00001110' ; AN0 Analog input, AN1-4 Digital IO, ADRESH only (ADRESL discarded) MOVWF ADCON1 MOVLW B'01000001' ; AD conv ON, AN0 Selected, Fosc/8 (T(AD)=1us) BANKSEL ADCON0 MOVWF ADCON0 CLRF PORTB ; Make all PORT B outputs low CLRF TMR0 ; Reset Timer 0 MOVLW 0x04 ; Startup Brightness ("dim") MOVWF BRITE BSF DIM ; Restore Threshold from EEPROM BANKSEL EEADR ; Select Bank of EEADR MOVLW 0x00 MOVWF EEADR ; Data Memory Address to read (0x00) BANKSEL EECON1 ; Select Bank of EECON1 BCF EECON1 , EEPGD ; Point to Data memory BSF EECON1 , RD ; EE Read BANKSEL EEDATA ; Select Bank of EEDATA MOVF EEDATA , W ; W = EEDATA BANKSEL THRLVL MOVWF THRLVL ; Restored Threshold BSF SDA ; I2C idle BSF SCL MOVLW 0x60 ; Set Prescaler second byte (stealth mode) MOVWF DB2 CALL DEBOUNCE ; Clock Stabilization delay 16 ms CALL TUNE ; Set tuner frequency MAIN BSF ADCON0,GO ; Start A/D (RSSI) CONV0 NOP BTFSC ADCON0, GO ; Test if done GOTO CONV0 MOVFW ADRESH ; Move 8 bit A/D result to W SUBWF MAXH,0 ; Subtract W from MAXH BTFSC STATUS,C ; result larger than MAXH? GOTO MAIN ; No MOVFW ADRESH MOVWF MAXH ; New MAXH GOTO MAIN TETRA4S ; Subroutine ; Tests if 4 seconds have elapsed ; Converts MAXH to LED bar DECFSZ T4S,1 RETURN MOVLW 0xF2 ; 0xF2 for 4s MOVWF T4S CALL LEDBAR MOVWF TEMPBAR CLRF MAXH ; Destroy Max Hold value CALL CHECKTHR ; Check threshold, beep if reached RETURN LEDBAR ; MAXH contains RSSI max value ; LED bar pattern is in W MOVFW MAXH ADDLW 0x9A ; LEVEL > -40 dBm BTFSS STATUS ,C GOTO LEDS7F MOVLW 0xFF ; Fullscale RETURN LEDS7F MOVFW MAXH ADDLW 0xA5 ; LEVEL > -48 dBm BTFSS STATUS ,C GOTO LEDS3F MOVLW 0x7F RETURN LEDS3F MOVFW MAXH ADDLW 0xAF ; LEVEL > -56 dBm BTFSS STATUS ,C GOTO LEDS1F MOVLW 0x3F RETURN LEDS1F MOVFW MAXH ADDLW 0xBA ; LEVEL > -64 dBm BTFSS STATUS ,C GOTO LEDS0F MOVLW 0x1F RETURN LEDS0F MOVFW MAXH ADDLW 0xC5 ; LEVEL > -72 dBm BTFSS STATUS ,C GOTO LEDS07 MOVLW 0x0F RETURN LEDS07 MOVFW MAXH ADDLW 0xD0 ; LEVEL > -80 dBm BTFSS STATUS ,C GOTO LEDS03 MOVLW 0x07 RETURN LEDS03 MOVFW MAXH ADDLW 0xDA ; LEVEL > -88 dBm BTFSS STATUS ,C GOTO LEDS01 MOVLW 0x03 RETURN LEDS01 MOVFW MAXH ADDLW 0xE3 ; LEVEL > -96 dBm BTFSS STATUS ,C GOTO LEDS00 MOVLW 0x01 RETURN LEDS00 MOVLW 0x00 ; LEVEL at noise floor -108 dBm RETURN ; Set frequency of tuner TUNE BCF INTCON , GIE ; Disable global interrupts CALL I2CSTART MOVLW 0xC0 ; Address CALL I2CBYTE MOVLW 0x34 ; Prescaler first byte CALL I2CBYTE MOVFW DB2 ; Get Prescaler second byte CALL I2CBYTE MOVLW 0xCA ; Control Byte CALL I2CBYTE MOVLW 0x90 ; Port Byte (Mid Band) CALL I2CBYTE CALL I2CSTOP BCF INTCON , TMR0IF ; Clear TMR0 interrupt just in case BSF INTCON , GIE ; Enable global interrupts RETURN I2CSTART BCF SDA CALL DELAY10US BCF SCL CALL DELAY10US RETURN I2CBYTE MOVWF I2CBUF MOVLW 0x08 MOVWF I2CCNT NEXTBIT BCF STATUS ,C ; Clear carry BCF SDA ; Glitch if next bit is 1 again UGLY! RLF I2CBUF ,1 BTFSC STATUS ,C BSF SDA CALL DELAY10US BSF SCL ; Send clock CALL DELAY10US BCF SCL CALL DELAY10US ; Done clock DECFSZ I2CCNT,1 GOTO NEXTBIT BCF SDA ; Fake ACK CALL DELAY10US BSF SCL CALL DELAY10US BCF SCL CALL DELAY10US RETURN I2CSTOP BCF SDA CALL DELAY10US BSF SCL CALL DELAY10US BSF SDA RETURN DELAY10US MOVLW 0x14 ; 33 us delay MOVWF I2CDELAY LOOP0 DECFSZ I2CDELAY,1 GOTO LOOP0 RETURN DEBOUNCE ; Subroutine, used in THR setting and INIT MOVLW 0xFF ; 96 ms outer delay MOVWF I2CCNT LOOP1 MOVLW 0xFF ; 0.39 ms inner delay MOVWF I2CDELAY LOOP2 DECFSZ I2CDELAY,1 GOTO LOOP2 DECFSZ I2CCNT,1 GOTO LOOP1 RETURN BARBRITE ; Subroutine (called from within INT handler) ; Modifies BAR brightness after BRT is pressed ; Debounce (every 16 ms) BTFSC BRT ; Test BRT Button GOTO NOBRT BTFSC BRTBTN ; BRT Button still pressed? RETURN BSF BRTBTN BTFSC NITE GOTO DIMBRT BTFSC DIM GOTO DAYBRT BTFSC DAY GOTO FULLBRT BCF FULL BSF NITE MOVLW 0x01 MOVWF BRITE RETURN DIMBRT BCF NITE BSF DIM MOVLW 0x04 MOVWF BRITE RETURN DAYBRT BCF DIM BSF DAY MOVLW 0x20 MOVWF BRITE RETURN FULLBRT BCF DAY BSF FULL MOVLW 0xF0 MOVWF BRITE RETURN NOBRT BCF BRTBTN RETURN THRSET ; Subroutine (called from within INT handler) ; User interface to change threshold for alarm ; All LEDs are full on because the PWM brightness control uses the interrupt BTFSC THR ; Test THR Button GOTO NOTHR THR1 CLRF LEDS ; switch off LEDs CALL DEBOUNCE ; 0.1 s delay BTFSS THR ; THR Button still pressed? GOTO THR1 THR2 MOVFW THRLVL MOVWF LEDS ; Show threshold MOVWF TEMPTHR THR3 BTFSS THR ; THR button? GOTO DECTHR BTFSS BRT ; BRT button? GOTO INCTHR GOTO THR3 ; INC threshold INCTHR CLRF LEDS ; switch off LEDs CALL DEBOUNCE CALL DEBOUNCE ; 0.2 s delay MOVFW THRLVL SUBLW 0xFF ; FF? BTFSS STATUS,Z GOTO INC7F GOTO DONETHR ; yes, exit INC INC7F MOVFW THRLVL SUBLW 0x7F BTFSS STATUS,Z GOTO INC3F MOVLW 0xFF MOVWF THRLVL GOTO DONETHR INC3F MOVFW THRLVL SUBLW 0x3F BTFSS STATUS,Z GOTO INC1F MOVLW 0x7F MOVWF THRLVL GOTO DONETHR INC1F MOVFW THRLVL SUBLW 0x1F BTFSS STATUS,Z GOTO INC0F MOVLW 0x3F MOVWF THRLVL GOTO DONETHR INC0F MOVFW THRLVL SUBLW 0x0F BTFSS STATUS,Z GOTO INC07 MOVLW 0x1F MOVWF THRLVL GOTO DONETHR INC07 MOVFW THRLVL SUBLW 0x07 BTFSS STATUS,Z GOTO INC03 MOVLW 0x0F MOVWF THRLVL GOTO DONETHR INC03 MOVLW 0x07 MOVWF THRLVL GOTO DONETHR ; DEC threshold DECTHR CLRF LEDS ; switch off LEDs CALL DEBOUNCE CALL DEBOUNCE ; 0.2 s delay MOVFW THRLVL SUBLW 0xFF ; FF? BTFSS STATUS,Z GOTO DEC7F MOVLW 0x7F MOVWF THRLVL GOTO DONETHR DEC7F MOVFW THRLVL SUBLW 0x7F ; 7F? BTFSS STATUS, Z GOTO DEC3F MOVLW 0x3F MOVWF THRLVL GOTO DONETHR DEC3F MOVFW THRLVL SUBLW 0x3F BTFSS STATUS ,Z GOTO DEC1F MOVLW 0x1F MOVWF THRLVL GOTO DONETHR DEC1F MOVFW THRLVL SUBLW 0x1F BTFSS STATUS ,Z GOTO DEC0F MOVLW 0x0F MOVWF THRLVL GOTO DONETHR DEC0F MOVFW THRLVL SUBLW 0x0F BTFSS STATUS,Z GOTO DEC07 MOVLW 0x07 MOVWF THRLVL GOTO DONETHR DEC07 MOVFW THRLVL SUBLW 0x07 BTFSS STATUS,Z GOTO DONETHR MOVLW 0x03 MOVWF THRLVL ; There's no lower threshold, that'd be silly ; Done manipulating threshold DONETHR BTFSC THR ; THR button? GOTO THR2 ; No MOVFW THRLVL CALL DEBOUNCE ; 0.1 s delay BTFSC THR ; Still THR button? GOTO THR2 ; Yes, exit and restore THR CLRF LEDS ; switch off LEDs MOVFW TEMPTHR ; Restore THR MOVWF THRLVL THR4 CALL DEBOUNCE ; to enable releasing THR button BTFSS THR GOTO THR4 CALL DEBOUNCE ; Store THRLVL into EEPROM (copied from datasheet) BANKSEL EECON1 ; Select Bank of EECON1 BTFSC EECON1 , WR ; Wait for write GOTO $-1 ; to complete BANKSEL EEADR ; Select Bank of EEADR MOVLW 0x00 MOVWF EEADR ; Data Memory Address to write BANKSEL THRLVL MOVFW THRLVL BANKSEL EEDATA MOVWF EEDATA ; Data Memory Value to write BANKSEL EECON1 ; Select Bank of EECON1 BCF EECON1 , EEPGD ; Point to DATA memory BSF EECON1 , WREN ; Enable writes MOVLW 0x55 MOVWF EECON2 ; Write 55h MOVLW 0xAA MOVWF EECON2 ; Write AAh BSF EECON1 , WR ; Set WR bit to begin write BCF EECON1 , WREN ; Disable writes BANKSEL PORTB ; Select BANK0 NOTHR RETURN CHECKTHR ; Subroutine called from TETRA4S ; Checks if threshold is reached MOVFW TEMPBAR SUBWF THRLVL, 0 BTFSC STATUS,Z GOTO PIP RETURN ; Creates "pip" PIP MOVLW B'00111101' BANKSEL TRISA MOVWF TRISA ; RA7,6,1 Outputs, 5-2,0 Inputs (ALARM output) MOVLW 0xAA ; 64 ms outer delay BANKSEL I2CCNT MOVWF I2CCNT LOOP3 MOVLW 0xFF ; 0.39 ms inner delay MOVWF I2CDELAY LOOP4 DECFSZ I2CDELAY,1 GOTO LOOP4 MOVLW B'00000010' XORWF PORTA ,1 ; Toggle ALARM DECFSZ I2CCNT,1 GOTO LOOP3 MOVLW B'00111111' BANKSEL TRISA MOVWF TRISA ; RA7,6 Outputs, 5-0 Inputs (ALARM Hi Z to minimize pop) BCF STATUS, RP0 ; Select bank 0 RETURN END |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4043 |
My only assembler was a brief dabble with Z80 about 3 years ago. It's a bit of a big ask Lewis, IMO you need to bite the bullet yourself and go through the code line by line looking up the mnemonics (I think it's the PIC18F instruction set) and commenting as you go, e.g. CHECKTHR ; Subroutine called from TETRA4S ; Checks if threshold is reached ; MOVFW TEMPBAR ; Move value from TEMPBAR into W. SUBWF THRLVL, 0 ; Subtract W from value in THRLVL and store back in W. BTFSC STATUS,Z ; If the Z bit of value in the STATUS register is zero (meaning the ; result of the previous subtraction was not zero) then skip the ; next instruction. GOTO PIP ; Jump to the PIP routine. RETURN ; Return from the CHECKTHR routine. I *think* the equivalent MMBasic probably looks something like Sub CHECKTHR If TEMPBAR = THRLVL Then PIP() ' Call PIP routine End Sub Good luck, Tom Edited 2023-05-18 04:52 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
If you know what it does and, if there's some sort of user interface, what it looks like when it's running then IMHO it would be *far* easier to start from scratch and write something new in MMBasic that behaves like it. If you don't know what it does then my advice is to forget it. Unless you really love banging your head against walls, that is. :) OTOH, PIC assembler doesn't have that many commands (but they do have some horrible register addressing). Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
The first questions are "What is it?" and "What do you want to do with it?" Can you provide links for your sources for this code and this module? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2076 |
can't help with the de-assemble (as others have pointed out it is a big ask because you have to be privy to the mental processes of the original programmer), but if you want to write PIC ASM, consider using Great Cow Basic. It is very active and has had several recent updates. takes all (well, most) the grunt out of assembler. it is compiled and the F818 is one of thousands of PICs and AVRs it directly supports. You can go direct from GCB to programmed PIC if you have your tool chain set up right (I tend to go to a HEX file and manually burn). You can examine the Assembler it generates and tweak if you need to (I rarely do, it does quite a good job if you ignore the non-pre-emptive setting of bank bits), you can also have inline Assembler in your basic source. No floating point, so all those fixed point tricks you used 40 years ago will benefit. I use it for simpler projects or where speed is needed. here is an example of some code of mine to show how easy it is to use (and uses a diminutive 12F508 to do something useful). ' ----- Configuration #chip 12F508,4 #config osc = int, wdt=on #define Approx1s 996 #define ConA 16 #define ConB 32 START: ' assign the prescaler to the WDT 'ASM [ movlw B'10001111' option ' ] DIM mm AS WORD DIM nn AS BYTE DIM RLMAP(2) AS BYTE ' this is the bit pattern to toggle DIM DLY AS WORD DIR GPIO b'11001110' ' GPIO.0 OUT ' n/c but could be used as "alive" indicator with an LED ' GPIO.1 IN ' dip switch bit 0 ' GPIO.2 IN ' dip switch bit 1 ' GPIO.3 IN ' dip switch bit 2 ' GPIO.4 OUT ' RL1 - PORTA ' GPIO.5 OUT ' RL2 - PORTB Wait1s ' pause a little after boot nn=(GPIO / 2) AND 7 ' read the switches (have to right shift) RLMAP(0)=ConA ' preset the most common config to save code RLMAP(1)=ConB DLY=10 SELECT CASE nn CASE =0 ' disconnect both PORTs RLMAP(0)=0:RLMAP(1)=0 CASE =1 ' PORTA static RLMAP(1)=ConA CASE =2 ' PORTB static RLMAP(0)=ConB CASE =3 ' 2 mins toggle DLY=120 CASE =4 ' 10 mins toggle DLY=600 CASE =5 ' 30 mins toggle DLY=1800 CASE =6 ' 60 mins toggle DLY=3600 CASE =7 ' 120 mins toggle DLY=7200 END SELECT Main: FOR nn=0 to 1 FOR mm=1 TO DLY GPIO=RLMAP(nn) + (mm and 1) Wait1s NEXT NEXT GOTO Main Sub Wait1s clrwdt PAUSE Approx1s clrwdt end sub and the assembler from it ;Program compiled by Great Cow BASIC (1.00.00 2023-04-13 (Windows 64 bit) : Build 1237) for Microchip MPASM/MPLAB-X Assembler using FreeBASIC 1.07.1/2023-04-14 CRC29 ;Need help? ; See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums, ; Check the documentation and Help at http://gcbasic.sourceforge.net/help/, ;or, email us: ; w_cholmondeley at users dot sourceforge dot net ; evanvennn at users dot sourceforge dot net ;******************************************************************************** ;Set up the assembler options (Chip type, clock source, other bits and pieces) LIST p=12F508, r=DEC #include <P12F508.inc> __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _OSC_INTRC ;******************************************************************************** ;Set aside memory locations for variables DELAYTEMP EQU 7 ; 0x7 DELAYTEMP2 EQU 8 ; 0x8 DLY EQU 14 ; 0xE DLY_H EQU 15 ; 0xF MM EQU 18 ; 0x12 MM_H EQU 19 ; 0x13 NN EQU 11 ; 0xB OPTION_REG EQU 20 ; 0x14 RLMAP EQU 29 ; 0x1D SYSBYTETEMPX EQU 7 ; 0x7 SYSTEMP1 EQU 21 ; 0x15 SYSTEMP1_H EQU 22 ; 0x16 SYSTEMP2 EQU 23 ; 0x17 SYSWAITTEMPMS EQU 9 ; 0x9 SYSWAITTEMPMS_H EQU 10 ; 0xA SYSWORDTEMPA EQU 12 ; 0xC SYSWORDTEMPA_H EQU 13 ; 0xD SYSWORDTEMPB EQU 16 ; 0x10 SYSWORDTEMPB_H EQU 17 ; 0x11 ;******************************************************************************** ;Alias variables SYSRLMAP_0 EQU 29 SYSRLMAP_1 EQU 30 ;******************************************************************************** ;Vectors ;Start of program memory page 0 ORG 0 ;Indirect jumps to allow calls to second half of page goto BASPROGRAMSTART Delay_MS goto SysInd_Delay_MS INITSYS goto SysInd_INITSYS SYSCOMPEQUAL16 goto SysInd_SYSCOMPEQUAL16 WAIT1S goto SysInd_WAIT1S BASPROGRAMSTART ;Call initialisation routines call INITSYS ;Start of the main program START movlw 143 option movlw 206 tris GPIO call WAIT1S bcf STATUS,C rrf GPIO,W movwf SysTemp2 movlw 7 andwf SysTemp2,W movwf NN movlw 16 movwf SYSRLMAP_0 movlw 32 movwf SYSRLMAP_1 movlw 10 movwf DLY clrf DLY_H SysSelect1Case1 movf NN,F btfss STATUS, Z goto SysSelect1Case2 clrf SYSRLMAP_0 clrf SYSRLMAP_1 goto SysSelectEnd1 SysSelect1Case2 decf NN,W btfss STATUS, Z goto SysSelect1Case3 movlw 16 movwf SYSRLMAP_1 goto SysSelectEnd1 SysSelect1Case3 movlw 2 subwf NN,W btfss STATUS, Z goto SysSelect1Case4 movlw 32 movwf SYSRLMAP_0 goto SysSelectEnd1 SysSelect1Case4 movlw 3 subwf NN,W btfss STATUS, Z goto SysSelect1Case5 movlw 120 movwf DLY clrf DLY_H goto SysSelectEnd1 SysSelect1Case5 movlw 4 subwf NN,W btfss STATUS, Z goto SysSelect1Case6 movlw 88 movwf DLY movlw 2 movwf DLY_H goto SysSelectEnd1 SysSelect1Case6 movlw 5 subwf NN,W btfss STATUS, Z goto SysSelect1Case7 movlw 8 movwf DLY movlw 7 movwf DLY_H goto SysSelectEnd1 SysSelect1Case7 movlw 6 subwf NN,W btfss STATUS, Z goto SysSelect1Case8 movlw 16 movwf DLY movlw 14 movwf DLY_H goto SysSelectEnd1 SysSelect1Case8 movlw 7 subwf NN,W btfss STATUS, Z goto SysSelectEnd1 movlw 32 movwf DLY movlw 28 movwf DLY_H SysSelectEnd1 MAIN movlw 255 movwf NN SysForLoop1 incf NN,F movlw 1 movwf MM clrf MM_H SysForLoop2 movlw low(RLMAP) addwf NN,W movwf FSR movlw 1 andwf MM,W movwf SysTemp1 clrf SysTemp1_H movf SysTemp1,W addwf INDF,W movwf GPIO call WAIT1S movf MM,W subwf DLY,W movwf SysTemp1 movf DLY_H,W movwf SysTemp1_H movf MM_H,W movwf SysTemp2 btfss STATUS,C incf SysTemp2,W subwf SysTemp1_H,F movf SysTemp1,W movwf SysWORDTempA movf SysTemp1_H,W movwf SysWORDTempA_H clrf SysWORDTempB clrf SysWORDTempB_H call SYSCOMPEQUAL16 comf SysByteTempX,F btfss SysByteTempX,0 goto ENDIF1 incf MM,F btfsc STATUS,Z incf MM_H,F goto SysForLoop2 ENDIF1 SysForLoopEnd2 movlw 1 subwf NN,W btfss STATUS, C goto SysForLoop1 SysForLoopEnd1 goto MAIN BASPROGRAMEND sleep goto BASPROGRAMEND ;******************************************************************************** SysInd_Delay_MS incf SysWaitTempMS_H, F DMS_START movlw 142 movwf DELAYTEMP2 DMS_OUTER movlw 1 movwf DELAYTEMP DMS_INNER decfsz DELAYTEMP, F goto DMS_INNER decfsz DELAYTEMP2, F goto DMS_OUTER decfsz SysWaitTempMS, F goto DMS_START decfsz SysWaitTempMS_H, F goto DMS_START retlw 0 ;******************************************************************************** SysInd_INITSYS movwf OSCCAL ;asm showdebug This code block sets the internal oscillator to ChipMHz ;asm showdebug _Complete_the_chip_setup_of_BSR,ADCs,ANSEL_and_other_key_setup_registers_or_register_bits movlw 199 option movlw 199 movwf OPTION_REG clrf GPIO retlw 0 ;******************************************************************************** SysInd_SYSCOMPEQUAL16 clrf SYSBYTETEMPX movf SYSWORDTEMPA, W subwf SYSWORDTEMPB, W btfss STATUS, Z retlw 0 movf SYSWORDTEMPA_H, W subwf SYSWORDTEMPB_H, W btfss STATUS, Z retlw 0 comf SYSBYTETEMPX,F retlw 0 ;******************************************************************************** SysInd_WAIT1S clrwdt movlw 228 movwf SysWaitTempMS movlw 3 movwf SysWaitTempMS_H call Delay_MS clrwdt retlw 0 ;******************************************************************************** END I love to follow the ASM file and see what GCB did with my basic just a thought Edited 2023-05-18 05:19 by CaptainBoing |
||||
okwatts Regular Member Joined: 27/09/2022 Location: CanadaPosts: 59 |
I'm not sure if this is any help but oshonsoft.com has a PIC simulator with a basic compiler that looks quite good for some of the lower and midrange PIC chips. It has a nominal cost but might allow you to analyze the code and it does allow you to see the assembly code generated by the Basic compiler. You might be able to work backward and infer how you would code it in MMBasic. That being said looking at the user interface of your device and what it does is probably a more straight forward approach to getting the same functionality. |
||||
Bowden_P Senior Member Joined: 20/03/2019 Location: United KingdomPosts: 162 |
Hi lew247, The device is a Microchip PIC16F818. Giving your listing the briefest of scans, it uses an I2C interface to somewhere. I'm not familiar with this micro, and it has an unusual instruction "MOVFW", probably more likely an older version of "MOVF register-name,W", but I don't have the datasheet and can't check this immediately. CHECKTHR ; Subroutine called from TETRA4S ; Checks if threshold is reached MOVFW TEMPBAR SUBWF THRLVL, 0 BTFSC STATUS,Z GOTO PIP RETURN As per Thwill's explanation, CHECKTHR subroutine compares TEMPBAR with THRLVL and jumps to label PIP if TEMPBAR = THRLVL, otherwise RETURN's back to where CHECKTHR was called from. The variable THRLVL is written anywhere there is a "MOVWF THRLVL" instruction, such as in the "DONETHR" subroutine. See also :- ; Restore Threshold from EEPROM .... or ; INC threshold .... sequence of comparisons, or ; DEC threshold DECTHR .... sequence of comparisons. The code isn't strongly structured, using as it does many GOTO's, so would be more difficult to understand for a conversion to MMBASIC. As Mixtel90 says, if you know how the original worked, I would start from there. The PIC16F818 would likely have just 35 instructions to understand. Only some are used in your code, so getting the idea of the flow of the code shouldn't be too daunting - if rather time-consuming however! With best regards, Paul. Nothing so constant as change. |
||||
Andy-g0poy Regular Member Joined: 07/03/2023 Location: United KingdomPosts: 59 |
Assembler is simple, and as such it seems complex because you need a lot of it. The big problem is that you have to read it in conjunction with the datasheets for the uP concerned. You asked where LEDBAR get the dbm values from. Well I'm impressed with this code, it's actually got some comments in it! It's also nicely presented. Much better than many coders work. So LEDBAR does the outputting of the data to the leds. --- LEDBAR ; MAXH contains RSSI max value ; LED bar pattern is in W MOVFW MAXH --- Which tells you directly that the data comes from MAXH Note that MOVFW is a assembler directive not an actual command but it acts like one. It's just a bit of shorthand that saves the programmer typing in a lot of repetitive commands. W is the PIC "accumlator" register. If you then search for MAXH you will find that it gets it's data from the A/D convertor ADRESH There is a long list of code that converts the A/D values into the necessary dbm values... In mmbasic all of this can be done with the ADC commands which can also be set to generate an interrupt when the conversion is complete and the data is in the specified array. However as others have said it's pretty much pointless trying to covert this code the Pico MMbasic directly By all means use it as a guide as to what needs to be done, Just map out what you need to do, and then write the mmbasic routines, which will do a lot more than the assembler code will do and so will be much shorter. Andy |
||||
lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks everyone I spent most of the night going through the code with the help of the datasheet and I think I've got it now Basically it's measuring the voltage from an input and lighting a number of led's depending on the voltage Can anyone tell me if the ADC of the pic on page 81 of the datasheet here outputs a high number with the highest voltage input and working down as the voltage goes down, or start low and work up? The values are HEX DEC 0x9A 154 is this 2.5v or 0xA5 165 0xAF 175 0xBA 186 0xC5 197 0xD0 208 0xDA 218 0xE3 227 or is this 2.5v 0x00 0 |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4250 |
Hi Lew, The only way a higher number from the A/D can relate to a lower voltage is when Vref- and Vref+ are swapped. That is possible with this chip, that both are connected to a external voltage source, in swapped polarity. But highly unlikely. So the higher number is the higher voltage....if you look at all the bits. Your numbers are 8 bit numbers, and the ADC is 10 bits. the 2 most significant bits are missing in your list unless the ADC is used in 8 bit mode). Looking at the application: converting output signal from a logaritmic amplifier (AD8307) most likely 10 bits are used. I am guessing this is some kind of power meter with LED signal bar. Since the AD8307 is really wide bandwidth (up to 5.8Ghz) this could come from communication equipment, WIFI scanners, satellite receivers, HAM applications, military stuff (military won't use a PIC16F818 though...no military (JAN . . versions..). Volhout Edited 2023-05-18 17:38 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
IanRogers Senior Member Joined: 09/12/2022 Location: United KingdomPosts: 151 |
I made it more readable. RSSI comes from the ADC It is saved in MAIN as MAXH then send to the TETRA4S routine to convert to display. This routine checks to see if the RSSI has reached a threshold to alarm the system. The donkey work is done in the ISR at the top. When a user presses the button a threshold can be set. It also clears the LED's so the can be updated ( seems to be time dependent, the LEDS can be differing brightness. ) The I2C is a software implementation. BUT.. No label, so a line or two may be missing. FYI... I cant seem to post code with indentations... Tabs don't work Edited 2023-05-18 17:41 by IanRogers I'd give my left arm to be ambidextrous |
||||
lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
MOVLW B'00001110' ; AN0 Analog input, AN1-4 Digital IO, ADRESH only (ADRESL discarded) Does this mean that it's only using 8 bit numbers? Is there an easy way to explain how you'd get an 8 bit number from a 10 bit input in basic? BTW am I correct in thinking the output from the AD8307 is a voltage and nothing else? Edited 2023-05-18 18:11 by lew247 |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2140 |
The first leading space gets cropped for some reason so use two or more leading spaces and code boxes indent ok. Like this. |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Multiple spaces are deleted in normal HTML. To preserve indentation, use the "code" button above the edit box, or put your code within the tags "[ CODE][ /CODE]" without the space after "[" which keeps the tags from being acted on in this post. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
IanRogers Senior Member Joined: 09/12/2022 Location: United KingdomPosts: 151 |
I did that but it's still HTML. I always use code tags. I use MANY forums and most see at least the first tab.. I'd give my left arm to be ambidextrous |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
I never use tabs, only spaces, so maybe that's why I haven't seen what you saw. Tabs are treated so differently based on program or settings that I find it easier to just use spaces. CODE tags (in upper case on this forum) work for me: Some indentation Some further indentation Back again PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4043 |
Only the devil uses tabs to indent code. Sure as eggs is eggs you will end up with a mix of tabs and spaces, and then someone will view the code on an editor with a different tab setting (2 vs. 4 vs. 8 characters) and the formatting will look completely screwed up to them - MMBasic firmware source I am looking at you . I believe every modern IDE has a setting so that the TAB key outputs a configurable number of spaces instead of the actual TAB character - and I *hope* they all default to this. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
IanRogers Senior Member Joined: 09/12/2022 Location: United KingdomPosts: 151 |
@lew247 Do you still need the breakdown? CheckThreshold (CHECKTHR) Has the threshold in variable TEMPBAR. This was obtained by reading the ADC and storing in MAXH, then the LEDBAR routine converts to -dbm. It is compared to the store variable THRLVL. ( which is set in INCTHR or the DECTHR routine called from THRSET from the ISR routine ) The pip routine sounds when its exceeded. Threshold set (THRSET) calls the INTHR and DECTHR and sets the level as needed THRLVL. DONETHR is how you described.. Its the endpoint of the THRSET routine. LEDBAR sets the LED configuration the variable TEMPBAR derived from MAXH converted to -dbm TETRA4S checks the 4 seconds have elapsed and updates the LED's if it has. MAIN is the main of course.. the RSSI (MAXH) is set up the converted when LEDBAR is called. CONV0 is the conversion loop. The pic is busy converting so it waits until the GO bit is clear before moving on. The only thing I can't determine is what the I2C is talking to I dont know address 0x60 but he call's it a tuner?? Edited 2023-05-19 22:40 by IanRogers I'd give my left arm to be ambidextrous |
||||
Quazee137 Guru Joined: 07/08/2016 Location: United StatesPosts: 572 |
0x060 may be something in this list 0x060 Quazee137 |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Interesting link there to https://i2cdevices.org/devices I had a good scan through--thanks. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Page 1 of 3 |
Print this page |