Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Advice how to get help to convert it to all to ASM?

Status
Not open for further replies.

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
Advice

I found some code on the internet that is suppose to do a big part of a a little hobby project I'm working on.

problem:
it's written in a combination of "C" but mostly asm. and is for a 16f876A PIC

advice:
how is the best way to get help to convert it to all asm. along with for a 16f676 pic.
if I can convert it and it does work I can add it to some code I have already written (in asm.)for the final project.
I'm fairly new at programming and have to teach myself as I go.
so this is for learning as much as completing the project.

thank
 

millwood

Advanced Member level 3
Joined
Jul 2, 2009
Messages
734
Helped
80
Reputation
164
Reaction score
35
Trophy points
1,308
Activity points
5,088
Advice

how is the best way to get help to convert it to all asm.

the best way to convert a piece of code is to first understand what it does and then how it does it. and then you can implement it in a way that you are comfortable with.

it is generally true that it takes as much time to understand someone's code as to write your own, if not more.
 

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
Re: Advice

Thanks millwood I do agree with what your saying.
I've found for "me" the best way to learn is to take something small that works
and expand on it. each time I add a small part (baby steps if you will) I learn a "little more. Right now I don't have the confidence to reinvent the wheel but I do have the desire to change it to fit my own needs. At the stage in my life I've also found it best to learn on_a_as_need_bases
there's really (I hope) only 2 areas that I need help on converting form "C"
to asm. If some one could explain in very simple terms what this does and what I need to change I would be very greatful
the 1st. I believe has to do with integers


Code:
int   n_bits;
int   n_bytes;
int   counter;
int   recv_reg;
int   send_reg;
int   nEmpty;
int   status_byte;
int   send_command;
int   general_flags;
int   nB8Count;
int   nB8;
int   nA8Count;
int   nA8;
int   status_response;
int   nCmdCount;
int   special_word;
int   photo_flag;

and the second with putting values
in to variables

Code:
void main()
{
   // Initialization
   //
   n_bits            = 0;
   counter           = 0;
   recv_reg          = 1;
   send_reg          = 0;
   nEmpty            = 0;
   status_byte       = 1;
   general_flags     = 0;
   nB8               = 4;
   nB8Count          = 0;
   nA8               = 3;
   nA8Count          = 0;
   status_response   = 1;
   special_word      = 0x0f;
   nCmdCount         = 10;
   send_command          = 0;
   photo_flag =0;
 

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,065
Reputation
4,130
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,269
Advice

That code doesn't do anything very useful. The first section reserves memory space for a load of variables, the second section puts initial values into the memory locations. Maybe you could post the whole program?

Keith
 

    homemade24

    Points: 2
    Helpful Answer Positive Rating

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
that what I thought Keith1200rs
what I need to know is how to do this in asm were it will compile
here the whole code

Code:
******************************************************************
//
//      LANC controller
//
//**********************************************************************
//
//  Control a Sony DSC-V1 still camera with a 16f876A PIC
//
//  Original code: Alberto Caballero Tante
//
//**********************************************************************
//
//  This is a beta version of a Sony LANC controller. LANC output
//  is on bit 3 of PIC Port C. Connect the camera using a pullup
//  resistor.
//
//
//**********************************************************************
//
//  21/10/2005: Beta version
//
//**********************************************************************
//
// Please any commets: [email]translib@hotmail.com[/email] (subject "LANC controller").
//
//**********************************************************************


#include "F:\Alberto\Aplicaciones\CCS Compiler\PIC projects\test_lanc\serie01.h"

int   n_bits;
int   n_bytes;
int   counter;
int   recv_reg;
int   send_reg;
int   nEmpty;
int   status_byte;
int   send_command;
int   general_flags;
int   nB8Count;
int   nB8;
int   nA8Count;
int   nA8;
int   status_response;
int   nCmdCount;
int   special_word;

int photo_flag;



#define     PORTA          0x05
#define     PORTB          0x06
#define     PORTC          0x07
#define     TRISA          0x85
#define     TRISB          0x86
#define     TRISC          0x87
#define     same           0x01
#define     no_same        0x00
#define     lanc           0x03
#define     STATUS         0x03
#define     RP0            0x05
#define     RP1            0x06
#define     msb            0x07
#define     lsb            0x00
#define     PC             0x02
#define     Z_BIT          0x02

#define     command_tx     0x00

#define     TrisLanc       0x01
#define     Tris           0x11

#define     EMPTY_COUNT    0x1D
#define     BitStatus0     0x00
#define     BitStatus1     0x02
#define     BitStatus2     0x03
#define     BitStatus3     0x04
#define     BitStatus4     0x05
#define     Bit0ECommand   0x01

#define     Bit0           0x00
#define     Bit1           0x01
#define     Bit2           0x02

// Commands
#define     COMMAND_0E     0x0E
#define     PRE_CMD_1E     0x1E
#define     POWER_OFF      0x5E
#define     PHOTO          0x5A
#define     WORD1          0x43
#define     WORD2          0x53
#define     SEND_CMD       0x01

#define     OUTPUT_PINS    0x00
#define     INPUT_PINS     0xFF


void main()
{
   // Initialization
   //
   n_bits            = 0;
   counter           = 0;
   recv_reg          = 1;
   send_reg          = 0;
   nEmpty            = 0;
   status_byte       = 1;
   general_flags     = 0;
   nB8               = 4;
   nB8Count          = 0;
   nA8               = 3;
   nA8Count          = 0;
   status_response   = 1;
   special_word      = 0x0f;
   nCmdCount         = 10;
   send_command          = 0;


   photo_flag =0;


   #asm

               bcf      STATUS, RP0
               bcf      STATUS, RP1

               clrf     n_bytes
   sync_up:    clrf     counter
   sync_loop:  btfss    PORTC, lanc
               goto     sync_up
               nop
               incfsz    counter, same
               goto     sync_loop
   synced:     clrf     n_bytes

   wait_strt:  btfsc    PORTC, lanc
               goto     wait_strt

   start_bit:  movlw    15
               movwf    counter
   l1:         decfsz   counter, same
               goto     l1

               btfsc    PORTC, lanc
               goto     error

               movlw    8
               movwf    n_bits

   wait_bits:  movlw    15
               movwf    counter
   l2:         decfsz   counter, same
               goto     l2

   send_bits:  btfss    general_flags, command_tx
               goto     wait_half
               btfss    send_reg, lsb
               goto     send_0

   send_1:     bcf      PORTC, lanc
               bsf      STATUS, RP0
               movlw    OUTPUT_PINS
               movwf    TRISC
               //bcf      STATUS, RP0
               nop
               nop
               goto     bit_sent

   send_0:     bsf      PORTC, lanc
               bsf      STATUS, RP0
               movlw    INPUT_PINS
               movwf    TRISC
               bcf      STATUS, RP0
               nop
               nop

   bit_sent:   rrf      send_reg, same
               movlw    10
               goto     jump_half

   wait_half:  movlw    15
   jump_half:
               movwf    counter
   l3:         decfsz   counter, same
               goto     l3

   read_bits:
               rrf      recv_reg, same
               bcf      recv_reg, msb
               btfss    PORTC, lanc
               bsf      recv_reg, msb
               nop
               nop

               decfsz   n_bits, same
               goto     wait_bits

   wait_stop:  movlw    14
               movwf    counter
   l4:         decfsz   counter, same
               goto     l4

   send_stop:  btfss    general_flags, command_tx
               goto     wait_half_stop
               bsf      PORTC, lanc
               bsf      STATUS, RP0
               movlw    INPUT_PINS
               movwf    TRISC
               bcf      STATUS, RP0
               bcf      general_flags, command_tx
               movlw    11
               goto     jump_half_stop


   wait_half_stop:
               movlw    14

   jump_half_stop:
               movwf    counter
   l5:         decfsz   counter, same
               goto     l5

   read_stop:  btfss    PORTC, lanc
               goto     error

   count:
               incf     n_bytes, same
               decf     n_bytes, w
               andlw    07
               addwf    PC, same
               goto     check_0
               goto     check_1
               goto     check_2
               goto     check_3
               goto     check_4
               goto     check_5
               goto     check_6
               goto     check_7

   //////////////////////////////////////////
   // Byte 0
   //////////////////////////////////////////
   check_0:
               btfss    send_command, 0
               goto     wait_strt

   send_command:
               movlw    PHOTO
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags
               goto     wait_strt

   //////////////////////////////////////////
   // Byte 1
   //////////////////////////////////////////
   check_1:
               btfss    status_byte, BitStatus2
               goto     wait_strt

   send_43:    // Send special values
               movf     special_word, no_same
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

               goto     wait_strt

   //////////////////////////////////////////
   // Byte 2
   //////////////////////////////////////////
   check_2:
               btfsc    status_byte, BitStatus0
               goto     status_0
               btfsc    status_byte, BitStatus1
               goto     status_1
               btfsc    status_byte, BitStatus3
               goto     status_2
               
               goto     wait_strt

   status_0:
               movlw    0
               addwf    recv_reg, no_same
               btfsc    STATUS, Z_BIT
               incf     nEmpty, same
               goto     wait_strt

   status_1:
               movlw    0x47
               subwf    recv_reg, no_same
               btfsc    STATUS, Z_BIT
               incf     nB8Count
               goto     wait_strt

   status_2:
               movlw    0x57
               subwf    recv_reg, no_same
               btfsc    STATUS, Z_BIT
               incf     nA8Count
               goto     wait_strt

   //////////////////////////////////////////
   // Byte 3
   //////////////////////////////////////////
   check_3:
               goto     wait_strt

   check_4:
               goto     wait_strt

   check_5:
               goto     wait_strt

   check_6:
               goto     wait_strt

   check_7:
               btfss    status_byte, Bit0ECommand
               goto     begin_spare

               // Send 0x0E command
               movlw    COMMAND_0E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags


   // Time to check the state
   begin_spare:
               btfsc    status_byte, BitStatus0
               goto     spare_status_0

               btfsc    status_byte, BitStatus1
               goto     spare_status_1

               btfsc    status_byte, BitStatus2
               goto     spare_status_2

               btfsc    status_byte, BitStatus3
               goto     spare_status_3

               goto     end_spare

   spare_status_0:
               movlw    EMPTY_COUNT
               subwf    nEmpty, no_same
               btfss    STATUS, Z_BIT
               goto     end_spare

               // Change status
               movlw    0x06
               movwf    status_byte

               // Send 0x0E command in next frame
               movlw    COMMAND_0E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

               goto     end_spare

   spare_status_1:
               movf     nB8, no_same
               subwf    nB8Count, no_same
               btfss    STATUS, Z_BIT
               goto     end_spare

               // Change status
               movlw    0x0A
               movwf    status_byte
               movlw    3
               movwf    nB8
               
               clrf     nB8Count

               //goto     end_spare

   spare_status_2: // Send AC, AC
               btfsc    status_response, Bit0
               goto     send_BC
               btfsc    status_response, Bit1
               goto     send_AC1
               btfsc    status_response, Bit2
               goto     send_AC2
               goto     error

   send_BC:
               // Change state
               movlw    0x02
               movwf    status_response

               // Prepare to send
               movlw    WORD1
               movwf    special_word
               goto     end_spare

   send_AC1:
               // Change state
               movlw    0x04
               movwf    status_response

               // Prepare to send
               movlw    WORD2
               movwf    special_word
               goto     end_spare

   send_AC2:
               // Change state
               movlw    0x01
               movwf    status_response
               movlw    0x12
               movwf    status_byte

               // Prepare to send
               movlw    WORD2
               movwf    special_word
               goto     end_spare

   spare_status_3: // Read A8's
               movf     nA8, no_same
               subwf    nA8Count, no_same
               btfss    STATUS, Z_BIT
               goto     end_spare

               // Change status
               movlw    0x06
               movwf    status_byte
               movlw    3
               movwf    nA8
               
               clrf     nA8Count

               movlw    0xff
               movwf    photo_flag;


   end_spare:
               btfss    photo_flag, 0x00
               goto     sync_up

               //movlw    0
               //movwf    photo_flag;

               bcf      status_byte, Bit0ECommand
               //bsf      status_byte, BitStatus4
               movlw       0xFF
               movwf       send_command

   pre_cmd:
               // Send 0x1E pre-command byte
               movlw    PRE_CMD_1E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

   check_count:
               decfsz   nCmdCount, same
               goto     sync_up


   end_cmd:
               // No more command. Restore state
               movlw    10
               movwf    nCmdCount
               //bcf      status_byte, BitStatus4
               movlw    0
               movwf    send_command
               bsf      status_byte, Bit0ECommand
               movlw    COMMAND_0E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

               movlw 0
               movwf  photo_flag

               goto     sync_up

luz:

   #endasm
      output_b(0xff);
   #asm

   goto fin
   error:

   #endasm
      while(1)
      {
         output_b(0xff);
         delay_ms(500);
         output_b(0x00);
         delay_ms(500);
      }
   #asm

   error2:
   #endasm
      while(1)
      {
         output_b(0xff);
         delay_ms(250);
         output_b(0x00);
         delay_ms(250);
      }
   #asm

   fin:
   #endasm
 

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,065
Reputation
4,130
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,269
I think all you need to do is reserve a bytes for each variable such as:


Code:
    cblock  0x20 (or whatever address free RAM starts at in that PIC)
   n_bits
   n_bytes
   counter
   recv_reg
   send_reg
  etc.

Then initialise the values. If any of the variables actually use two bytes (they are defined in that way) then you may have to allocate two bytes to it. I gues it may be safer to do that first until you understand the program. Something like:

Code:
    cblock 0x20
    n_bits
    n_bitsH
    n_bytes
    n_bytesH
etc.

The extra variable just reserves some space for the second byte in each case.

Keith.

Actually - I think you should add
Code:
    endc

at the end of the cblock statement. Excuse my PIC assembler - it's a while since I have done any.

Keith.
 

    homemade24

    Points: 2
    Helpful Answer Positive Rating

millwood

Advanced Member level 3
Joined
Jul 2, 2009
Messages
734
Helped
80
Reputation
164
Reaction score
35
Trophy points
1,308
Activity points
5,088
If some one could explain in very simple terms what this does

they simply declare the variables to be of integer type (16 or 32 bits, depending on your compiler / mcu), and then initiate them to zero.

all you need to do is to replicate those functions, aka declaring them to be integers and initialize them to zero, in assembly.

how hard could that be?
 

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
thank again Keith
that's some what of what I was trying as I was migrating to the 16f676

? marks and commits on anything I no sure on (really I'm sure sure of anything these days)

Code:
         #include "p16F676.inc"  
         
  __CONFIG  _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _MCLRE_OFF & _CPD_OFF
  
   errorlevel   -302
          cblock    0x20



   n_bits;
   n_bytes;
   counter;
   recv_reg;
   send_reg;
   nEmpty;
   status_byte;
   send_command;
   general_flags;
   nB8Count;
   nB8;
   nA8Count;
   nA8;
   status_response;
   nCmdCount;
   special_word;
   photo_flag;
   d1
   d2
   d3

  endc

#define       LED    PORTA
#define       LANC   PORTC 
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#define     same           0x01 ;
#define     no_same        0x00 ;
;#define     STATUS         0x03 ;
;#define     RP0            0x05 ;will not compile with these???
;#define     RP1            0x06 ;
#define     msb            0x07 ;
#define     lsb            0x00 ;
#define     PC             0x02 ; not sure if these have to be here ???
#define     Z_BIT          0x02 ;
#define     command_tx     0x00 ;
#define     TrisLanc       0x01 ;
#define     Tris           0x11 ;??????????????
#define     EMPTY_COUNT    0x1D ;
#define     BitStatus0     0x00 ;
#define     BitStatus1     0x02 ;
#define     BitStatus2     0x03 ;
#define     BitStatus3     0x04 ;
#define     BitStatus4     0x05 ;
#define     Bit0ECommand   0x01 ;
#define     Bit0           0x00 ;
#define     Bit1           0x01 ;
#define     Bit2           0x02 ;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;// Commands
#define     COMMAND_0E     0x0E
#define     PRE_CMD_1E     0x1E
#define     POWER_OFF      0x5E
#define     PHOTO          0x5A
#define     WORD1          0x43
#define     WORD2          0x53
#define     SEND_CMD       0x01

#define     OUTPUT_PINS    0x00
#define     INPUT_PINS     0xFE ;LEAVES PORTC.0 OUTPUT FOR LED


;//////////////////////////////TURN COMPARATOR OFF//////////////////////////////////////////
        bcf	STATUS,RP0	            ;BANK 0
		bcf	STATUS,RP1	            ; register page 0
		movlw	0X07		        ;SET UP W TO TURN COMPARATOR OFF 
		movwf	CMCON
;////////////////////////////SET UP I/O////////////////////////////////////////////////////        
        bSf	STATUS,RP0	            ; BANK 1
		movlw	b'00000000'	        ;CONFIG I/O
		movwf	TRISA	            ; 
        movlw	b'00000000'	        ;CONFIG I/O LANC INPUT @ POWER!!!!!!!!!!!!!!!!!!!
		movwf	TRISC	            ;TO ALL OUTPUTS
;/////////////////////////////SET UP A/D/////////////////////////////////////////////////
        MOVLW   B'00000000'         ; A/D OFF
        MOVWF   ANSEL               ;IS IN BANK 1

        
;//////////////////////////////////////SET OR CLEAR BITS @START UP///////////////////////

;???????????????????????????????????????????????
;???????????????????????????????????????????????

;
;void main()  ?? IS THIS NEEDED??
;{
   ;// Initialization
   ;//
  CLRF  PORTA
  CLRF  PORTC
  clrf  n_bits           ;= 0;
  clrf counter           ;= 0;   
  clrf send_reg          ;= 0;
  clrf nEmpty            ;= 0;
  clrf general_flags     ;= 0;
  clrf nB8Count          ;= 0;
  clrf nA8Count          ;= 0;
  clrf send_command      ;= 0;
  clrf photo_flag        ;= 0;
;????????????????????????????????????????
  BSF recv_reg,0          ;= 1;
  BSF status_byte,0       ;= 1;
  BSF status_response,0   ;= 1;
;???????????????????????????????????????
 
;?????????? I MAY NOT EVEN BE CLOSE ON THIS???????
;??????;special_word      = 0x0f;??????
                movlw    0X0F
                movwf   special_word  

 ;???????;nCmdCount         = 10;????????

                 movlw    10
                movwf   nCmdCount

;????????????;nA8   = 3;??????????????????
                movlw    3
                movwf   nA8
;?????????????; nB8 = 4;??????????????
                movlw   4
                movwf   nB8


;??????????????????????????????????????????????????
;??????????????????????????????????????????????????
 

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,065
Reputation
4,130
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,269
By the way, why not just run the software as it is first? I seem to think that there is a free version of the Microchip C compiler. Then at least you will know if it worth the effort hacking it around.

The void main() and curly brackets {} are to do with C so can be removed.

#define PC 0x02 depends on whether PC is used like that (I assume it is the program counter).

I am not sure about STATUS/RP0/RP1 - maybe they are already defined in your include file?

Once you reach the #asm statements you shouldn't need to change anything until you reach #endasm.

You really need the file serie01.h used in the program - do you have it?

Keith.
 

    homemade24

    Points: 2
    Helpful Answer Positive Rating

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,273
Helped
4,970
Reputation
9,962
Reaction score
4,803
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
129,655
Expanding on what Keith has said; you can declare 'int' storage spaces inside a cblock by appending ':2' to the variable name. The colon and number reserve that many bytes for the variable and makes sure the next variable in the list s moved along accordingly.
So your cblock could be rewritten as:
Code:
 cblock 0x20
 n_bits:2
 n_bytes:2
 counter:2
 recv_reg:2
 send_reg:2
 .
 .
 endc

You would do well to check the placement of the cblock as it is different from one PIC to another. It should be set no lower than the first free general purpose register address.

Also look inside the '.inc' file and see which register names, bit names and addresses are already defined. Once you have added the ',inc' to the top of your program, there is no need to redefine them. It's a text file which is easy to read, if you look inside the assembler output listing you will see it is simply included as text at the top of the program. That's why it's called '.inc', it is included wherever you put it in your program.

Another thing to make life easier for yourself is to use the 'banksel' command. It isn't a PIC instruction, its an assembler directive which tells it to produce the correct banking instructions automatically. It will save you having to remember which RP0 and RP1 bits are set at any time.

Brian.
 

    homemade24

    Points: 2
    Helpful Answer Positive Rating

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,065
Reputation
4,130
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,269
Brian,

Thanks for the advice. It is useful to know how to allocate 2 bytes. My PIC assembler is a bit rusty. I have managed to avoid it for a few years, doing C and using other make processors instead.

Keith
 

    homemade24

    Points: 2
    Helpful Answer Positive Rating

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
Thank you both for being so kind to help me.

You really need the file serie01.h used in the program - do you have it?
No I do not with out it I did not think I could compile in "C"
you both have given me some good ideals that I will work on
I should have posted this link earlier it's were I go the code and tell more about.it

https://dsc.ijs.si/damir.vrancic/personal/trv900/cameras/
thanks again
 

millwood

Advanced Member level 3
Joined
Jul 2, 2009
Messages
734
Helped
80
Reputation
164
Reaction score
35
Trophy points
1,308
Activity points
5,088
;#define RP0 0x05 ;will not compile with these???
;#define RP1 0x06 ;
#define PC 0x02 ; not sure if these have to be here ???

those are the registers and they are most likely defined in the stock include file.
 

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,065
Reputation
4,130
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,269
It might be worthwhile trying to compile it without the include file because the errors may tell you what you are missing. The delay() routine may be one thing unless it is part of the C compiler.

Keith
 

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
sorry had out of town family come to town will get back on this tomorrow
reading over all that is posted
thank and please stay with me on this
 

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
thanks again
ok I had a few hours to work on this afternoon
I tried to check everything posted here as well as make those changes
I'm still not sure if I have this part right
Code:
;?????????????????????????????????????????????????????????????????  
;;;;;;;;"c";;;;;;;;;;;;;special_word = 0x0f;
  movlw   0x0f              ;d15
  movwf    special_word
;;;;;;;;"c";;;;;;;;;;;;;;nCmdCount= 10;
  movlw      10 
  movwf   nCmdCount                      ;not sure if these 4 are right
;;;;;;;;;;"c";;;;;;;;;;;nA8 = 3;
  movlw      3
  movwf   nA8
;;;;;;;;;;"c";;;;;;;;;;;;;;;;nB8 = 4;
  movlw      4
  movwf   nB8
;??????????????????????????????????????????????????????????????????????
;??????????????????????????????????????????????????????????????????????
it does compile and but when testing the code when it get here to check the lanc line for clrf its still high
Code:
;?????????????????????????????????????????????????????????????????                
                 btfsc    LANC        ;btfsc
                  goto PROBLEM_2     ;error turn on red LED skip if lanc is clrf
;???????????????????????????????????????????????????????????????????????
so I guess the timings off or any one have thought on it
Code:
;07/25/10/9:00 pm

         #include "p16F676.inc"  
         
  __CONFIG  _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _MCLRE_OFF & _CPD_OFF
  
   errorlevel   -302
          cblock    0x20   ;20H-5FH ARE GENERAL PURPOSE REGISTERS

   n_bits:2;
   n_bytes:2;
   counter:2;
   recv_reg:2;
   send_reg:2;
   nEmpty:2;
   status_byte:2;
   send_command:2;
   general_flags:2;
   nB8Count:2;
   nB8:2;
   nA8Count:2;
   nA8:2;
   status_response:2;
   nCmdCount:2;
   special_word:2;
   photo_flag:2;
   
  endc

#define       RED    PORTC,0    ;TROUBLE LED
#define       LANC   PORTC,4    ;READ,WRITE TO CAM
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Removed what was predefined in the inclued file
#define     same           0x01 ;
#define     no_same        0x00 ;
#define     msb            0x07 ;
#define     lsb            0x00 ;
#define     PC             0x02 ; 
#define     Z_BIT          0x02 ;
#define     command_tx     0x00 ;
#define     TrisLanc       0x01 ;
#define     Tris           0x11 ;
#define     EMPTY_COUNT    0x1D ;
#define     BitStatus0     0x00 ;
#define     BitStatus1     0x02 ;
#define     BitStatus2     0x03 ;
#define     BitStatus3     0x04 ;
#define     BitStatus4     0x05 ;
#define     Bit0ECommand   0x01 ;
#define     Bit0           0x00 ;
#define     Bit1           0x01 ;
#define     Bit2           0x02 ;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Commands
#define     COMMAND_0E     0x0E
#define     PRE_CMD_1E     0x1E
#define     POWER_OFF      0x5E
#define     PHOTO          0x5A
#define     WORD1          0x43
#define     WORD2          0x53
#define     SEND_CMD       0x01
#define     OUTPUT_PINS    0x00
#define     INPUT_PINS     0xFE
 org 0
      nop
;//////////////////////////////TURN COMPARATOR OFF//////////////////////////////////////////
                                    ;bcf	STATUS,RP0	            ;BANK 0
		banksel CMCON               ; bcf	STATUS,RP1	    ; register page 0
		movlw	0X07		        ;SET UP W TO TURN COMPARATOR OFF 
		movwf	CMCON
;////////////////////////////SET UP I/O////////////////////////////////////////////////////        
       banksel CMCON                ;bSf	STATUS,RP0	            ; BANK 1
		movlw	b'11111111'	        ;CONFIG I/O
		movwf	TRISA	            ;2,3,4 INPUTS 
        movlw	b'00010000'	        ;CONFIG I/O LANC INPUT @ POWER!!!!!!!!!!!!!!!!!!!
		movwf	TRISC	            ;TO ALL OUTPUTS
;/////////////////////////////SET UP A/D/////////////////////////////////////////////////
        MOVLW   B'00000000'         ; TURN A/D OFF
        MOVWF   ANSEL               ;IS IN BANK 1      
;//////////////////////////////////////SET OR CLEAR BITS @START UP///////////////////////                      
  bcf RED                ;problem LED
  clrf   TRISA
  clrf   n_bits         ;= 0;"c"
  clrf counter          ;= 0;"c"
  clrf  send_reg        ;= 0;"c"
  clrf nEmpty           ;= 0;"c"
  clrf general_flags    ;= 0;"c"
  clrf send_command     ;= 0;"c"
  clrf nB8Count         ;= 0;"c"
  clrf nA8Count         ;= 0;"c"
  clrf  photo_flag      ;= 0;"c"
  bsf status_response,0   ;= 1;"c"
  bsf recv_reg,0          ;= 1;"c"
  bsf status_byte,0       ;= 1;"c"
;??????????????????????????????????????????????????????????????????  
;;;;;;;;"c";;;;;;;;;;;;;special_word = 0x0f;
  movlw   0x0f              ;d15
  movwf    special_word
;;;;;;;;"c";;;;;;;;;;;;;;nCmdCount= 10;
  movlw      10 
  movwf   nCmdCount                      ;not sure if these 4 are right
;;;;;;;;;;"c";;;;;;;;;;;nA8 = 3;
  movlw      3
  movwf   nA8
;;;;;;;;;;"c";;;;;;;;;;;;;;;;nB8 = 4;
  movlw      4
  movwf   nB8
;??????????????????????????????????????????????????????????????????????
;??????????????????????????????????????????????????????????????????????               
            clrf     n_bytes
sync_up:    clrf     counter
sync_loop:  btfss    LANC          
               goto     sync_up
               nop
               
               incfsz    counter, same 
               goto     sync_loop
synced:     clrf     n_bytes

wait_strt:  btfsc     LANC         
               goto     wait_strt
               
start_bit:  movlw    15
               movwf    counter
l1:         decfsz   counter, same 
               goto     l1
;?????????????????????????????????????????????????????????????????????????????                
                 btfsc    LANC        ;btfsc
                  goto PROBLEM_2     ;error turn on red LED skip if lanc is clrf
;????????????????????????????????????????????????????????????????????????????????
               movlw    8
               movwf    n_bits    ;n_bits=8

wait_bits:  movlw    15
               movwf    counter   
l2:         decfsz   counter, same 
               goto     l2

send_bits:  btfss    general_flags, command_tx 
               goto     wait_half
               btfss    send_reg, lsb
               goto     send_0

send_1:     bcf       LANC            
               banksel  TRISC         ;bsf      STATUS, RP0
               movlw    OUTPUT_PINS
               movwf    TRISC 
               nop
               nop
               goto     bit_sent

send_0:     bsf       LANC            ;set lanc and make input for reading
               banksel  TRISC  ;bsf      STATUS, RP0
               movlw    INPUT_PINS
               movwf    TRISC
               bcf      STATUS, RP0
               nop
               nop
               
bit_sent:   rrf      send_reg, same   ;shift out bits
               movlw    10
               goto     jump_half
                
wait_half:  movlw    15
jump_half:
               movwf    counter
l3:         decfsz   counter, same
               goto     l3

read_bits:
               rrf      recv_reg, same  ;read bits
               bcf      recv_reg, msb
               btfss    LANC            ;if Lanc is low set next
               bsf      recv_reg, msb
               nop
               nop

               decfsz   n_bits, same   ;read 8 bits
               goto     wait_bits

wait_stop:  movlw    14
               movwf    counter
l4:         decfsz   counter, same     ;count down from 14
               goto     l4

send_stop:  btfss    general_flags, command_tx
               goto     wait_half_stop
               bsf      LANC
              bsf      STATUS, RP0
               movlw    INPUT_PINS
               movwf    TRISC
               bcf      STATUS, RP0   ;???????banksel
               bcf      general_flags, command_tx
               
               
               movlw    11
               goto     jump_half_stop


wait_half_stop:
               movlw    14

jump_half_stop:
               movwf    counter
l5:         decfsz   counter, same
               goto     l5

read_stop:  bsF     LANC         
               

count:
               incf     n_bytes, same
               decf     n_bytes, w
               andlw    07
               addwf    PC, same
               goto     check_0
               goto     check_1
               goto     check_2
               goto     check_3
               goto     check_4
               goto     check_5
               goto     check_6
               goto     check_7
  
check_0:
               
               btfsC    send_command, 0
               goto     wait_strt

send_commandS:
               
               movlw    PHOTO
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags
               goto     wait_strt
  
check_1: 
                     
               btfss    status_byte, BitStatus2
               goto     wait_strt

send_43:   
               
               movf     special_word, no_same
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags
               goto     wait_strt
  
check_2:
               btfsc    status_byte, BitStatus0
               goto     status_0
               btfsc    status_byte, BitStatus1
               goto     status_1
               btfsc    status_byte, BitStatus3
               goto     status_2
               goto     wait_strt

status_0:
               movlw    0
               addwf    recv_reg, no_same
               btfsc    STATUS, Z_BIT
               incf     nEmpty, same
               goto     wait_strt

status_1:
               movlw    0x47
               subwf    recv_reg, no_same
               btfsc    STATUS, Z_BIT
               incf     nB8Count
               goto     wait_strt

status_2:      
               
               movlw    0x57
               subwf    recv_reg, no_same
               btfsc    STATUS, Z_BIT
               incf     nA8Count
               goto     wait_strt

check_3:
               
               goto     wait_strt

check_4:
               
               goto     wait_strt

check_5:
               goto     wait_strt

check_6:
               goto     wait_strt

check_7:
              
               btfss    status_byte, Bit0ECommand
               goto     begin_spare

               movlw    COMMAND_0E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

               
begin_spare:
               btfsc    status_byte, BitStatus0
               goto     spare_status_0

               btfsc    status_byte, BitStatus1
               goto     spare_status_1

               btfsc    status_byte, BitStatus2
               goto     spare_status_2

               btfsc    status_byte, BitStatus3
               goto     spare_status_3

               goto     end_spare

spare_status_0:
               movlw    EMPTY_COUNT
               subwf    nEmpty, no_same
               btfss    STATUS, Z_BIT
               goto     end_spare

               ;// Change status
               movlw    0x06
               movwf    status_byte

               ;// Send 0x0E command in next frame
               movlw    COMMAND_0E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

               goto     end_spare
spare_status_1:
               movf     nB8, no_same
               subwf    nB8Count, no_same
               btfss    STATUS, Z_BIT
               goto     end_spare

              ;// Change status
               movlw    0x0A
               movwf    status_byte
               movlw    3
               movwf    nB8
               
               clrf     nB8Count

spare_status_2: ;// Send AC, AC
               btfsc    status_response, Bit0
               goto     send_BC
               btfsc    status_response, Bit1
               goto     send_AC1
               btfsc    status_response, Bit2
               goto     send_AC2
               

send_BC:
               movlw    0x02
               movwf    status_response

               ;// Prepare to send
               movlw    WORD1
               movwf    special_word
               goto     end_spare

send_AC1:
               ;// Change state
               movlw    0x04
               movwf    status_response

               ;// Prepare to send
               movlw    WORD2
               movwf    special_word
               goto     end_spare

send_AC2:
               ;// Change state
               movlw    0x01
               movwf    status_response
               movlw    0x12
               movwf    status_byte

               ;// Prepare to send
               movlw    WORD2
               movwf    special_word
               goto     end_spare

spare_status_3: ;// Read A8's
               movf     nA8, no_same
               subwf    nA8Count, no_same
               btfss    STATUS, Z_BIT
               goto     end_spare

               ;// Change status
               movlw    0x06
               movwf    status_byte
               movlw    3
               movwf    nA8
               
               clrf     nA8Count

               movlw    0xff
               movwf    photo_flag;


end_spare:
               btfss    photo_flag, 0x00
               goto     sync_up

               ;//movlw    0
               ;//movwf    photo_flag;

               bcf      status_byte, Bit0ECommand
               ;//bsf      status_byte, BitStatus4
               movlw       0xFF
               movwf       send_command

pre_cmd:
               ;// Send 0x1E pre-command byte
               movlw    PRE_CMD_1E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

check_count:
               decfsz   nCmdCount, same
               goto     sync_up


end_cmd:
               ;// No more command. Restore state
               movlw    10
               movwf    nCmdCount
               ;//bcf      status_byte, BitStatus4
               movlw    0
               movwf    send_command
               bsf      status_byte, Bit0ECommand
               movlw    COMMAND_0E
               movwf    send_reg
               movlw    SEND_CMD
               movwf    general_flags

               movlw 0
               movwf  photo_flag

               goto     sync_up



PROBLEM_2
 bsf RED
      

      end
 

keith1200rs

Super Moderator
Staff member
Joined
Oct 9, 2009
Messages
10,877
Helped
2,065
Reputation
4,130
Reaction score
1,597
Trophy points
1,403
Location
Yorkshire, UK
Activity points
57,269
Is your clock speed the same as the original code? The place where it gets stuck seems to be after a "start bit" loop which is executed 15 times to get a certain length pulse.

Keith.
 

homemade24

Junior Member level 1
Joined
Jun 28, 2008
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,415
Keith sorry for not getting back sooner I have been doing more research and looking @ different option what to try next
to answer you question I'm not sure I'm running a 4mz and the "C" code does not list it
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top