Help for 16F690

t06afre

Joined May 11, 2009
5,934
It could be a problem related to your Windows OS. Are you running the newest version of MPLAB. Your kit may have been produced some yers ago. And hence the software CDs will not be up to data. Do not bother with MPLABX. As I think it is still in beta versions.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Have tried to use another program to make the coding.
"Flowcode"
In virtuel it works fine, but when compiled and send to pic it will nok work at all.
It's a very simpel program, turning alle 4 light off, and when switch pressed it should light them all up.

But i do not......
Rich (BB code):
//************************************************************************************
//**  
//**  File name:     F:\test\Flowcode1.c
//**  Generated by:  Flowcode v4.3.9.65
//**  Date:          Friday, February 10, 2012 17:55:43
//**  Licence:       Free version
//**  
//**        ***FREE/DEMO VERSION***
//**  
//**  
//**     NOT FOR COMMERCIAL USE
//**  
//**  http://www.matrixmultimedia.com
//************************************************************************************

#define MX_PIC
//Defines for microcontroller
#define P16F690
#define MX_EE
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_BCB
#define MX_SPI_SDI 4
#define MX_SPI_SDO 7
#define MX_SPI_SCK 6
#define MX_UART
#define MX_UART_B
#define MX_UART_TX 7
#define MX_UART_RX 5
#define MX_I2C
#define MX_MI2C
#define MX_I2C_B
#define MX_I2C_SDA 4
#define MX_I2C_SCL 6
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_TRIS1 trisc
#define MX_PWM_1 5
//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
void FCM_Taend();
void FCM_Rul();

//Variable declarations
char FCV_TRYK;
 
//Macro implementations
void FCM_Taend()
{
 
}
void FCM_Rul()
{
 
}
void main()
{
 
 //Initialisation
 ansel = 0;
anselh = 0;

 //Interrupt initialisation code
 option_reg = 0xC0;

 //Loop
 //Loop: While 1
 while (1)
 {
  //Input
  //Input: A3 -> Tryk
  trisa = trisa | 0x08;
  FCV_TRYK = ((porta & 0x08) == 0x08);

  //Switch
  //Switch: Tryk?
  switch (FCV_TRYK)
  {
   case 1:
   {
    //Output
    //Output: 1 -> C0
    trisc = trisc & 0xfe;
    if (1)
     portc = (portc & 0xfe) | 0x01;
    else
     portc = portc & 0xfe;

    //Output
    //Output: 1 -> C1
    trisc = trisc & 0xfd;
    if (1)
     portc = (portc & 0xfd) | 0x02;
    else
     portc = portc & 0xfd;

    //Output
    //Output: 1 -> C2
    trisc = trisc & 0xfb;
    if (1)
     portc = (portc & 0xfb) | 0x04;
    else
     portc = portc & 0xfb;

    //Output
    //Output: 1 -> C3
    trisc = trisc & 0xf7;
    if (1)
     portc = (portc & 0xf7) | 0x08;
    else
     portc = portc & 0xf7;

    break;
   }
   default:
   {
    //Output
    //Output: 0 -> C0
    trisc = trisc & 0xfe;
    if (0)
     portc = (portc & 0xfe) | 0x01;
    else
     portc = portc & 0xfe;

    //Output
    //Output: 0 -> C1
    trisc = trisc & 0xfd;
    if (0)
     portc = (portc & 0xfd) | 0x02;
    else
     portc = portc & 0xfd;

    //Output
    //Output: 0 -> C2
    trisc = trisc & 0xfb;
    if (0)
     portc = (portc & 0xfb) | 0x04;
    else
     portc = portc & 0xfb;

    //Output
    //Output: 0 -> C3
    trisc = trisc & 0xf7;
    if (0)
     portc = (portc & 0xf7) | 0x08;
    else
     portc = portc & 0xf7;

   }
  }

 }

 mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}
 
Last edited by a moderator:

thatoneguy

Joined Feb 19, 2009
6,359
I'd give Microchip an email problem form submission. This is the first time I've not seen it work out of the box with the sample code, ever, and that counts a ton of PICKits.

Hooking it up backwards shouldn't kill the PICKit 2/3 so that shouldn't be an issue. The PK2 read your target's voltage and automatically switched.

Are you compiling the source files above into a .hex file in MPLAB before trying to program the chip with the PICKit2?

Try fully uninstalling MPLAB and the PICKit 2 standalone software, then reboot, and re-install both.

There's no reason MPLAB can't compile one of it's samples as given above:
Rich (BB code):
Make: The target "C:\PK2 Lessons\LPC Demo Board\01 Hello World\Hello World.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q  /p16F690 "Hello World.asm" /l"Hello World.lst" /e"Hello World.err"
Error[105]   C:\PK2 LESSONS\LPC DEMO BOARD\01 HELLO WORLD\HELLO  WORLD.ASM 32 : Cannot open file (Include File "AC162061.inc" not found)
Message[302] C:\PK2 LESSONS\LPC DEMO BOARD\01 HELLO WORLD\HELLO  WORLD.ASM 38 : Register in operand not in bank 0.  Ensure that bank bits  are correct.
Halting build on first failure as requested.
It cannot find an include file.

Can you READ the .hex file from the PIC that came with a running program?
 

t06afre

Joined May 11, 2009
5,934
I did dig up my PICKIT 2, and the same board as the OP. I tried to get the same error. But could not provoke the same error. As Thatoneguy said those kits are meant to work out of the box. And they have always done that for me. Do you have the programming tool bar. Marked with a red circle? You will not get this toolbar unless a programmer unit is connected in MPLAB
 

Attachments

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Sure , i have that, it also read and write to and from the device,
now i have uninstalled it all, see if i get time to install it again tomorrow,
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Have re installed all.
When i load "blink.asm" into MPLAB 8.60 and export it, and save the hex file.
Load the hex file into pickit2, Warning : Hex file loaded is larger than device.

When i try the original hex files from pickit2 , it loads without problems, and the board works.

Try to load the original ASM file "blink.asm again into MPLAB, and program device from mplab, it says...
Rich (BB code):
Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power not detected - Powering from PICkit 2 ( 5.00V)
PIC16F690 found (Rev 0x6)
PICkit 2 Ready
Programming Target (11-02-2012  12:03:21)
PIC16F690 found (Rev 0x6)
Erasing Target
Programming Configuration Memory
Verifying Configuration Memory
PICkit 2 Ready
But board will not work.
 

t06afre

Joined May 11, 2009
5,934
I might see why you have some problems. First of all. Then you do something in MPLAB. ALWAYS create a project. The project wizard is very helpful in creating a project. See project->project wizard. Then you want to edit open the workspace file. (files with file name *.mcw) Second you have to use the "Make" or "Build All" before programming the chip after changes ;)
You should also know that the button on your demo board is connected to the MCLR pin (RA3). On your chip you can select if this PIN is standard input or MCLR. In all the examples this pin will not be used as MLCR but a standard input. However the PICKIT 2 take control over this pin. So the button will not work until the PICKIT is removed. You may control the MCLR pin from MPLAB also. In the picture posted in post #25. The function for this is in programmer menu. Or the "arrow up" "arrow down" symbols in the programmer toolbar
 

thatoneguy

Joined Feb 19, 2009
6,359
Have re installed all.
When i load "blink.asm" into MPLAB 8.60 and export it, and save the hex file.
Load the hex file into pickit2, Warning : Hex file loaded is larger than device.

When i try the original hex files from pickit2 , it loads without problems, and the board works.

Try to load the original ASM file "blink.asm again into MPLAB, and program device from mplab, it says...
Rich (BB code):
Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power not detected - Powering from PICkit 2 ( 5.00V)
PIC16F690 found (Rev 0x6)
PICkit 2 Ready
Programming Target (11-02-2012  12:03:21)
PIC16F690 found (Rev 0x6)
Erasing Target
Programming Configuration Memory
Verifying Configuration Memory
PICkit 2 Ready
But board will not work.
Ok, there are 3 parts to programming:

Read config for OSCcAL and other "chip specific values".
Erase Flash/Program Memory
Program Flash/Program Memory
Program EEPROM Memory
Program Config Data back to chip, even if it is unchanged.

You somehow have it only programing the config data, and not the program and EEPROM area with the .hex file.
 

thatoneguy

Joined Feb 19, 2009
6,359
Have re installed all.
When i load "blink.asm" into MPLAB 8.60 and export it, and save the hex file.
Load the hex file into pickit2, Warning : Hex file loaded is larger than device.

When i try the original hex files from pickit2 , it loads without problems, and the board works.

Try to load the original ASM file "blink.asm again into MPLAB, and program device from mplab, it says...
Rich (BB code):
Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power not detected - Powering from PICkit 2 ( 5.00V)
PIC16F690 found (Rev 0x6)
PICkit 2 Ready
Programming Target (11-02-2012  12:03:21)
PIC16F690 found (Rev 0x6)
Erasing Target
Programming Configuration Memory
Verifying Configuration Memory
PICkit 2 Ready
But board will not work.
Ok, there are 3 parts to programming, which normally happen very quickly in one step:

Read config for OSCcAL and other "chip specific values".
Erase Flash/Program Memory
Program Flash/Program Memory
Program EEPROM Memory
Program Config Data back to chip, even if it is unchanged.

You somehow have it only programing the config data, and not the program and EEPROM area with the .hex file.

You are a lot further along than yesterday. If you find the .hex file and use the standalone PICKit 2 program, you should be able to load the entire thing without an issue.
 

t06afre

Joined May 11, 2009
5,934

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Is it possible to find and use a grafics verions, like flowcode that i could build the files in ?
It's too complicated to make it in c, or other languages,
it's easy for you that have been educated in programming.
 

spinnaker

Joined Oct 29, 2009
7,830
Is it possible to find and use a grafics verions, like flowcode that i could build the files in ?
It's too complicated to make it in c, or other languages,
it's easy for you that have been educated in programming.
C is not all that hard. You can also program in BASIC or Pascal. Both very easy too.

I doubt any flow chart program is going to be able to allow you to turn out anything very useful.

You really need to learn programming. Some think you need to learn assembler but I do not agree. I think you can understand the MCU just as well in C.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Some explaning would be nice here.
Rich (BB code):
; *******************************************************************
; PICkit 2 Lesson 2 - "Blink"
;
; First lesson showed how to make an LED turn on,
; Now we'll look at how to make it blink.  Delay loops are necessary
; to slow down the on and off commands so they are visible to humans.
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F690 requires the AC162061 header for debugging  *
; *******************************************************************
#include <p16F690.inc>
    __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
    cblock 0x20
Delay1                   ; Define two file registers for the
Delay2                   ; delay loop
     endc
      
     org 0
Start:
     bsf       STATUS,RP0          ; select Register Page 1
     bcf       TRISC,0             ; make IO Pin B.0 an output
     bcf       STATUS,RP0          ; back to Register Page 0
MainLoop:
     bsf       PORTC,0             ; turn on LED C0
OndelayLoop:
     decfsz    Delay1,f            ; Waste time.  
     goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
     decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
     goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
                                   ; call it a two-tenths of a second.
      
     bcf       PORTC,0             ; Turn off LED C0
OffDelayLoop:
     decfsz    Delay1,f            ; same delay as above
     goto      OffDelayLoop
     decfsz    Delay2,f
     goto      OffDelayLoop
     goto      MainLoop            ; Do it again...
     end
decfsz Delay1,f
goto OndelayLoop , How can the process know how long to make the delay ? on step by step, it just repeting this again and again..
 

spinnaker

Joined Oct 29, 2009
7,830
Some explaning would be nice here.
Rich (BB code):
; *******************************************************************
; PICkit 2 Lesson 2 - "Blink"
;
; First lesson showed how to make an LED turn on,
; Now we'll look at how to make it blink.  Delay loops are necessary
; to slow down the on and off commands so they are visible to humans.
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F690 requires the AC162061 header for debugging  *
; *******************************************************************
#include <p16F690.inc>
    __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
    cblock 0x20
Delay1                   ; Define two file registers for the
Delay2                   ; delay loop
     endc
      
     org 0
Start:
     bsf       STATUS,RP0          ; select Register Page 1
     bcf       TRISC,0             ; make IO Pin B.0 an output
     bcf       STATUS,RP0          ; back to Register Page 0
MainLoop:
     bsf       PORTC,0             ; turn on LED C0
OndelayLoop:
     decfsz    Delay1,f            ; Waste time.  
     goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
     decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
     goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
                                   ; call it a two-tenths of a second.
      
     bcf       PORTC,0             ; Turn off LED C0
OffDelayLoop:
     decfsz    Delay1,f            ; same delay as above
     goto      OffDelayLoop
     decfsz    Delay2,f
     goto      OffDelayLoop
     goto      MainLoop            ; Do it again...
     end
decfsz Delay1,f
goto OndelayLoop , How can the process know how long to make the delay ? on step by step, it just repeting this again and again..
It is simply the time it takes to execute each instruction.
http://pcbheaven.com/picpages/Instruction_Cycle_Duration_and_Programmable_Delays/
 

t06afre

Joined May 11, 2009
5,934
DECFSZ Decrement f, Skip if 0
Syntax: [ label ] DECFSZ f,d
Operands: 0 ≤ f ≤ 127
d ∈ [0,1]
Operation: (f) - 1 → (destination);
skip if result = 0
Status Affected: None
Description: The contents of register ‘f’ are
decremented. If ‘d’ is ‘0’, the result
is placed in the W register. If ‘d’ is
‘1’, the result is placed back in
register ‘f’.
If the result is ‘1’, the next
instruction is executed. If the
result is ‘0’, then a NOP is
executed instead, making it a
two-cycle instruction.

MLAB use a symbolic assembler. So instead of writing 0 or 1, that say nothing. The Assembler accept f or w, which give some meaning. If you look at TABLE 15-1: OPCODE FIELD DESCRIPTIONS You will see that under field d. The value defaults to 1, or f. So you may only write decfsz Delay1
I can not remember that I have used the w option any time at all​
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
getting there ;)
but have some more ?,
When i make a program, and it takes ex, 0.5 second to run past. and my input will only last for ex 0.4 sec, then it will not be able to read the input as high ?

How do i make a 24 hour watch in the program, it should be a seperat timer or something ?
 
Top