Help for 16F690

thatoneguy

Joined Feb 19, 2009
6,359
Take a look at MikroBasic, Swordfish SE, PicBasic Pro, or the Oshonsoft PIC Simulator Basic (fairly visually oriented).

BASIC is quick to pick up and you can get going and get your project done. You will still need to know basic, and know how ports and registers on the '690 work (Read the datasheet, ask a lot of questions here).

I am of the school that you don't need to start in assembly if you've never programmed before. A high level language, such as Basic, which most people can work with, will get you up in running in a week. The code will probably be more compact and faster running than a big program written in assembly by a beginner.

All of the compilers listed above have demo versions, the PIC Simulator is cheapest at $49, and Swordfish SE is generous with the demo to the point many use it without buying it due to small projects.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Been playing a little, ;)
Rich (BB code):
;Chip Settings
#chip 16F690,4
;Defines (Constants)
#define LCD_IO 4
#define LCD_RW PORTB.4
#define LCD_RS PORTB.5
#define LCD_Enable PORTB.6
#define LCD_DB4 PORTC.0
#define LCD_DB5 PORTC.1
#define LCD_DB6 PORTC.2
#define LCD_DB7 PORTC.3
;Variables
Dim Regn As integer
Dim RegnTotal As integer
Tjek:
If PORTA.0 = 1 Then
MM
End If
If PORTA.1 = 1 Then
ResetTotal
End If
Goto Tjek
'''Millimeter
Sub MM
Regn = Regn +1
RegnTotal = RegnTotal+1
End Sub
Sub ResetTotal
RegnTotal = 0
End Sub
Or even i ASM.
Rich (BB code):
;********************************************************************************
;Set up the assembler options (Chip type, clock source, other bits and pieces)
 LIST p=16F690, r=DEC
#include <P16F690.inc>
 __CONFIG _INTOSC & _WDT_OFF & _MCLRE_OFF
;********************************************************************************
;Set aside memory locations for variables
REGN EQU 32
REGN_H EQU 33
REGNTOTAL EQU 34
REGNTOTAL_H EQU 35
;********************************************************************************
;Vectors
 ORG 0
 goto BASPROGRAMSTART
 ORG 4
 retfie
;********************************************************************************
;Start of program memory page 0
 ORG 5
BASPROGRAMSTART
;Call initialisation routines
 call INITSYS
;Automatic pin direction setting
 banksel TRISA
 bsf TRISA,1
 bsf TRISA,0
;Start of the main program
TJEK
 banksel PORTA
 btfsc PORTA,0
 call MM
 btfsc PORTA,1
 call RESETTOTAL
 goto TJEK
BASPROGRAMEND
 sleep
 goto $
;********************************************************************************
INITSYS
 movlw 143
 banksel OSCCON
 andwf OSCCON,F
 movlw 96
 iorwf OSCCON,F
 banksel ADCON0
 bcf ADCON0,ADON
 bcf ADCON0,ADFM
 banksel ANSEL
 clrf ANSEL
 clrf ANSELH
 bcf CM2CON0,C2ON
 bcf CM1CON0,C1ON
 banksel PORTA
 clrf PORTA
 clrf PORTB
 clrf PORTC
 return
;********************************************************************************
MM
 movlw 1
 addwf REGN,F
 movlw 0
 btfsc STATUS,C
 addlw 1
 addwf REGN_H,F
 movlw 1
 addwf REGNTOTAL,F
 movlw 0
 btfsc STATUS,C
 addlw 1
 addwf REGNTOTAL_H,F
 return
;********************************************************************************
RESETTOTAL
 clrf REGNTOTAL
 clrf REGNTOTAL_H
 return
;********************************************************************************
;Start of program memory page 1
 ORG 2048
 END
It read on 2 inputs.
A = when new rain comes , it adds 1 to today and total rain.
B = When pressed it resettotal rain.

Will it work , i have not made the readout yet ?
BTW , how do i make sure it only counts one time from input A ?
 

t06afre

Joined May 11, 2009
5,934
Can i use timer0 for generating an interrupt every minute ?
The most used technique/method is to connect a 32768 Hz watch crystal to timer 1. By using some programming tricks you can get an interrupt every second. The programming for this is not on a beginner level. But it is not that hard either. Timer 0 can be used as counter for the rain signal
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
I was planing to use the timer as signal for a 24 hour clock.
Like every minute it will interrupt and add 1 to minute,
Also wondering, how to store data in EE Prom, so that if power is lost, it will remember the data.
 

spinnaker

Joined Oct 29, 2009
7,830
The most used technique/method is to connect a 32768 Hz watch crystal to timer 1. By using some programming tricks you can get an interrupt every second. The programming for this is not on a beginner level. But it is not that hard either. Timer 0 can be used as counter for the rain signal
And if if the interrupt needs to be less than a second then you can simply have a counter that counts the number of ticks for a second.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Hi,
Can't seem to get any life in the LCD.
Here is the code.
only in 4 bit mode, d0-d3 on lcd is grounded,
have this here LCD.
https://www.elfaelektronik.dk/elfa3~dk_da/elfa/init.do?item=75-512-37&toc=0

Rich (BB code):
;********************************************************************************
;Set up the assembler options (Chip type, clock source, other bits and pieces)
 LIST p=16F690, r=DEC
#include <P16F690.inc>
 __CONFIG _INTOSC & _WDT_OFF & _MCLRE_OFF
;********************************************************************************
;Set aside memory locations for variables
DELAYTEMP EQU 112
DELAYTEMP2 EQU 113
SYSSTRINGLENGTH EQU 118
SysCalcTempA EQU 117
SysCalcTempB EQU 121
SysCalcTempX EQU 112
SysStringA EQU 119
SysStringA_H EQU 120
SysStringB EQU 114
SysStringB_H EQU 115
SysWaitTemp10US EQU 117
SysWaitTempMS EQU 114
SysWaitTempMS_H EQU 115
SysWaitTempS EQU 116
SYSSTRINGPARAM1 EQU 345
LCDBYTE EQU 32
LCDCOLUMN EQU 33
LCDLINE EQU 34
LCDREADY EQU 35
PRINTLEN EQU 36
SYSLCDTEMP EQU 37
SYSPRINTTEMP EQU 38
StringPointer EQU 39
SysPRINTDATAHandler EQU 40
SysPRINTDATAHandler_H EQU 41
SysTemp1 EQU 42
;********************************************************************************
;Vectors
 ORG 0
 goto BASPROGRAMSTART
 ORG 4
 retfie
;********************************************************************************
;Start of program memory page 0
 ORG 5
BASPROGRAMSTART
;Call initialisation routines
 call INITSYS
 call INITLCD
;Start of the main program
 call LCD
 movlw 5
 movwf SysWaitTempS
 call Delay_S
TJEK
 movlw 1
 movwf SysWaitTempS
 call Delay_S
 goto TJEK
BASPROGRAMEND
 sleep
 goto $
;********************************************************************************
CLS
 bcf PORTC,6
 movlw 1
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movlw 2
 movwf SysWaitTempMS
 clrf SysWaitTempMS_H
 call Delay_MS
 movlw 128
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movlw 10
 movwf SysWaitTemp10US
 goto Delay_10US
;********************************************************************************
Delay_10US
D10US_START
 movlw 2
 movwf DELAYTEMP
DelayUS0
 decfsz DELAYTEMP,F
 goto DelayUS0
 decfsz SysWaitTemp10US, F
 goto D10US_START
 return
;********************************************************************************
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
 return
;********************************************************************************
Delay_S
DS_START
 movlw 232
 movwf SysWaitTempMS
 movlw 3
 movwf SysWaitTempMS_H
 call Delay_MS
 decfsz SysWaitTempS, F
 goto DS_START
 return
;********************************************************************************
INITLCD
 banksel TRISC
 bcf TRISC,6
 bcf TRISC,5
 bcf TRISC,7
 movlw 10
 movwf SysWaitTempMS
 clrf SysWaitTempMS_H
 banksel STATUS
 call Delay_MS
SysWaitLoop2
 call FN_LCDREADY
 movf LCDREADY,F
 btfsc STATUS,Z
 goto SysWaitLoop2
 bcf PORTC,6
 banksel TRISC
 bcf TRISC,0
 bcf TRISC,1
 bcf TRISC,2
 bcf TRISC,3
 banksel PORTC
 bcf PORTC,6
 bcf PORTC,5
 bcf PORTC,0
 bsf PORTC,1
 bcf PORTC,2
 bcf PORTC,3
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bsf PORTC,7
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,7
 movlw 5
 movwf SysWaitTempMS
 clrf SysWaitTempMS_H
 call Delay_MS
 movlw 40
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movlw 25
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,6
 movlw 6
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 movlw 12
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 goto CLS
;********************************************************************************
INITSYS
 movlw 143
 banksel OSCCON
 andwf OSCCON,F
 movlw 96
 iorwf OSCCON,F
 banksel ADCON0
 bcf ADCON0,ADON
 bcf ADCON0,ADFM
 banksel ANSEL
 clrf ANSEL
 clrf ANSELH
 bcf CM2CON0,C2ON
 bcf CM1CON0,C1ON
 banksel PORTA
 clrf PORTA
 clrf PORTB
 clrf PORTC
 return
;********************************************************************************
LCD
 call CLS
 movlw 1
 movwf LCDLINE
 movlw 8
 movwf LCDCOLUMN
 call LOCATE
 movlw low SYSSTRINGPARAM1
 movwf SysStringB
 movlw high SYSSTRINGPARAM1
 movwf SysStringB_H
 movlw low StringTable1
 movwf SysStringA
 movlw high StringTable1
 movwf SysStringA_H
 call SysReadString
 movlw low SYSSTRINGPARAM1
 movwf SysPRINTDATAHandler
 movlw high SYSSTRINGPARAM1
 movwf SysPRINTDATAHandler_H
 call PRINT53
 movlw 2
 movwf LCDLINE
 movlw 8
 movwf LCDCOLUMN
 call LOCATE
 movlw low SYSSTRINGPARAM1
 movwf SysStringB
 movlw high SYSSTRINGPARAM1
 movwf SysStringB_H
 movlw low StringTable2
 movwf SysStringA
 movlw high StringTable2
 movwf SysStringA_H
 call SysReadString
 movlw low SYSSTRINGPARAM1
 movwf SysPRINTDATAHandler
 movlw high SYSSTRINGPARAM1
 movwf SysPRINTDATAHandler_H
 goto PRINT53
;********************************************************************************
LCDNORMALWRITEBYTE
SysWaitLoop1
 call FN_LCDREADY
 movf LCDREADY,F
 btfsc STATUS,Z
 goto SysWaitLoop1
 bcf PORTC,5
 banksel TRISC
 bcf TRISC,0
 bcf TRISC,1
 bcf TRISC,2
 bcf TRISC,3
 banksel PORTC
 bcf PORTC,0
 bcf PORTC,1
 bcf PORTC,2
 bcf PORTC,3
 btfsc LCDBYTE,7
 bsf PORTC,3
 btfsc LCDBYTE,6
 bsf PORTC,2
 btfsc LCDBYTE,5
 bsf PORTC,1
 btfsc LCDBYTE,4
 bsf PORTC,0
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bsf PORTC,7
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,7
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,0
 bcf PORTC,1
 bcf PORTC,2
 bcf PORTC,3
 btfsc LCDBYTE,3
 bsf PORTC,3
 btfsc LCDBYTE,2
 bsf PORTC,2
 btfsc LCDBYTE,1
 bsf PORTC,1
 btfsc LCDBYTE,0
 bsf PORTC,0
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bsf PORTC,7
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,7
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,3
 bcf PORTC,2
 bcf PORTC,1
 bcf PORTC,0
 return
;********************************************************************************
FN_LCDREADY
 clrf LCDREADY
 bcf SYSLCDTEMP,2
 btfsc PORTC,6
 bsf SYSLCDTEMP,2
 bsf PORTC,5
 bcf PORTC,6
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 bsf PORTC,7
 movlw 5
 movwf SysWaitTemp10US
 call Delay_10US
 banksel TRISC
 bsf TRISC,3
 banksel PORTC
 btfsc PORTC,3
 goto ENDIF12
 movlw 255
 movwf LCDREADY
ENDIF12
 bcf PORTC,7
 movlw 25
 movwf SysWaitTemp10US
 call Delay_10US
 bcf PORTC,6
 btfsc SYSLCDTEMP,2
 bsf PORTC,6
 return
;********************************************************************************
LOCATE
 bcf PORTC,6
 movf LCDLINE,W
 sublw 1
 btfsc STATUS, C
 goto ENDIF1
 movlw 2
 subwf LCDLINE,F
 movlw 20
 addwf LCDCOLUMN,F
ENDIF1
 movlw 64
 movwf SysCalcTempA
 movf LCDLINE,W
 movwf SysCalcTempB
 call SysMultSub
 movf LCDCOLUMN,W
 addwf SysCalcTempX,W
 movwf SysTemp1
 movlw 128
 iorwf SysTemp1,W
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movlw 5
 movwf SysWaitTemp10US
 goto Delay_10US
;********************************************************************************
;Overloaded signature: STRING:
PRINT53
 movf SysPRINTDATAHandler,W
 movwf FSR
 bcf STATUS, IRP
 btfsc SysPRINTDATAHandler_H,0
 bsf STATUS, IRP
 movf INDF,W
 movwf PRINTLEN
 movf PRINTLEN,F
 btfsc STATUS, Z
 return
 bsf PORTC,6
 clrf SYSPRINTTEMP
SysForLoop1
 incf SYSPRINTTEMP,F
 movf SYSPRINTTEMP,W
 addwf SysPRINTDATAHandler,W
 movwf FSR
 bcf STATUS, IRP
 btfsc SysPRINTDATAHandler_H,0
 bsf STATUS, IRP
 movf INDF,W
 movwf LCDBYTE
 call LCDNORMALWRITEBYTE
 movf PRINTLEN,W
 subwf SYSPRINTTEMP,W
 btfss STATUS, C
 goto SysForLoop1
 return
;********************************************************************************
SYSMULTSUB
 clrf SYSCALCTEMPX
MUL8LOOP
 movf SYSCALCTEMPA, W
 btfsc SYSCALCTEMPB, 0
 addwf SYSCALCTEMPX, F
 bcf STATUS, C
 rrf SYSCALCTEMPB, F
 bcf STATUS, C
 rlf SYSCALCTEMPA, F
 movf SYSCALCTEMPB, F
 btfss STATUS, Z
 goto MUL8LOOP
 return
;********************************************************************************
SYSREADSTRING
 movf SYSSTRINGB, W
 movwf FSR
 bcf STATUS, IRP
 btfsc SYSSTRINGB_H, 0
 bsf STATUS, IRP
 call SYSSTRINGTABLES
 movwf SYSCALCTEMPA
 movwf INDF
 addwf SYSSTRINGB, F
 goto SYSSTRINGREADCHECK
SYSREADSTRINGPART
 movf SYSSTRINGB, W
 movwf FSR
 bcf STATUS, IRP
 btfsc SYSSTRINGB_H, 0
 bsf STATUS, IRP
 call SYSSTRINGTABLES
 movwf SYSCALCTEMPA
 addwf SYSSTRINGLENGTH,F
 addwf SYSSTRINGB,F
SYSSTRINGREADCHECK
 movf SYSCALCTEMPA,F
 btfsc STATUS,Z
 return
SYSSTRINGREAD
 call SYSSTRINGTABLES
 incf FSR, F
 movwf INDF
 decfsz SYSCALCTEMPA, F
 goto SYSSTRINGREAD
 return
;********************************************************************************
SysStringTables
 movf SysStringA_H,W
 movwf PCLATH
 movf SysStringA,W
 incf SysStringA,F
 btfsc STATUS,Z
 incf SysStringA_H,F
 movwf PCL
StringTable1
 retlw 4
 retlw 68 ;D
 retlw 97 ;a
 retlw 118 ;v
 retlw 115 ;s

StringTable2
 retlw 4
 retlw 68 ;D
 retlw 111 ;o
 retlw 111 ;o
 retlw 111 ;o

;********************************************************************************
;Start of program memory page 1
 ORG 2048
 END
 

t06afre

Joined May 11, 2009
5,934
A common beginner error is to forget about the contrast setting see figure "1-5 POWER SUPPLY CIRCUIT AND CONTRAST ADJUST" Also timing during the LCD setup is VERY important se figure "5-3-2 4 BIT MODE" If you push the commands to quickly to the LCD during setup. You will typical get a blank display or in some cases just square boxes. Did you made the code by yourself, or did you use something found on the net? You may cut some corners by using code from good sites. Take a look here http://www.piclist.com/techref/io/lcd/pic.htm I took a look quick at your code. And my gut feeling say it will not work. But I leave the debugging to you:D. Take a look here post#1 for debugging tips using MPLAB
Last note then posting questions like this Always include both chematics and code. Drawing schematics should not be a problem for you
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
thx, could you give me some hint in where the problem is ?

Btw i use "Great Cow Graphical BASIC " for making the code.
Every other things with led works ok, so the program makes ok files.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Well. found 1 software error and 1 hardware error.
Hardware = did use 2*5 kohm resistor i serial, and just use the middle to contrast.
Found a 10 kohm pot, and allmost ground the contrast and i works.
Software error , line 0 should be the top line, and line 1 is second, ( stupid me )
now i works,
 

Attachments

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
can i use RA3 and mount a 32,768 khz crystal.
let timer1 run intil interrupt at 255 = 128 times
and make a counter that counts to 128*60 and then i will have a tick every "minute"
 

t06afre

Joined May 11, 2009
5,934
No certainly not. RA3 is the MCLR pin. Timer1 is the timer to use with 32,768 KHz crystal. Connect the crystal between the RA5/OSC1 and RA4/OSC2 pins. The datasheet say how to do it. Timer1 is 16 bit so it will roll over and causing interrupt (if enabled correct;) ) every 2. second. Given that you set the prescaler to 1. Should be OK for your project I guess
 
Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
my mistake, couldent remeber the pin,
will try tomorrow. and make a counter that count to 30, that give 1 minute tick.
 
Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
699
Seem to have a problem
what could be the problem in this code ??
hen this section is in my code, it will not assemble to Hex,
program just freezes,
Rich (BB code):
Do Until PORTB.5 = 1
If PORTB.6 = 1 Then
if dow= "Sondag then
dow = "Mandag"
end if
If dow= "Lordag" Then
dow = "Sondag"
end if
if dow= "Fredag" then
dow= "Lordag"
end if
if dow= "Torsdag" then
dow= "Fredag"
end if
if dow= "Onsdag" then
dow= "Torsdag"
end if
if dow= "Tirsdag" then
dow= "Onsdag"
end if
if dow= "Mandag" then
dow = "Tirsdag"
end if
End If
Wait 250 ms
End If
Locate 1, 7
LCDWriteChar 255
Wait 250 ms
Locate 1, 7
Print dow
Wait 250 ms
Loop
 
Top