Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic16f877a CCP1-LCD

Status
Not open for further replies.

Avatar1

New Member
Hi Guys

Hay I’m fairly new to all this programming but have been reading some threads on here and have read the MPlab tutorial so have a basic idea on how to start my programming project. So please be patient if I ask stupid questions :).

So my set up I’m using
Chip: PIC16F877A
External Clock: using 8mhz crystal
Prototyping board scrounged from college
Software: MPLab IDE

(Please ask if you require further details)

Now I have a signal from an oscillator which varies roughly from 100hz to 1500hz. I wish to use the CCP on the Pic to sample the changing frequency of the oscillator. I then wish it to display values on a LCD screen.

Now the questions so brace your self:

How do I go about setting up (producing code) so that I can use the CCP on the pic to sample my frequency?
Is there any demo code that i could use and edit for my purposes or a link to a thread on here or website that can point me guide me on how to use this feature on the pic. I have read the Data sheet for the device but as I previously mentioned I am a beginner to PIC chip world.

Now with the LCD its pretty much the same question is there any code available or guidance on how to set this up with my PIC?

After reading the MPlab tutorial I also believe that I will require a stimulus in order to simulate my program that I hope to make with help from you guys. How do i produce a stimulus in order to recreate my signal from my oscillator?

Anywho hope I haven’t asked to many questions for you! But any help would be appreciated as I’m soo new to this programming. In any further information is required please ask

Thanks again any help is appreciated

Mark
 
I would suggest doing it in stages - always better to write code like that.

First off I would suggest getting an LCD working, displaying a simple text message or whatever. This then becomes a valuable debugging tool for writing your frequency checking code.

There is LCD code and connection details in my tutorials, you're welcome to 'steal' that :D
 
Hay

Thanks for the links. Just some more info im useing a 1 x 16 LCD display from everbouquet and i noticed on the LCD tutorial that nigel uses a 2 x 16 what would need to be changed if anything?
 
Hay

Thanks for the links. Just some more info im useing a 1 x 16 LCD display from everbouquet and i noticed on the LCD tutorial that nigel uses a 2 x 16 what would need to be changed if anything?

Nothing, just ignore the second line.

LCD's are almost all 1x80 - with a 'window' on that buffer. Your 1x16 will show the first 16 bytes of that buffer, and you can scroll it along the buffer. A 2x16 has two 'windows' on the buffer, one at the start, and one 40 characters in.
 
So,

I’ve been having a go at using Mplab and as I have previously said this is my first time at this.

I decided I would write the code in steps as mentioned and have started on trying to set up the CCP in order to capture the each rising edge of my frequency and count the amount of clock pulses and storing this in the memory. I used the templates provided by microchip in order to initialize my chip (PIC16F877a) and this seemed to work fine when debugging the code. So I continued on to the next step.

After searching the internet I found the code below. After looking at it for a bit it seemed to be what I was after I think? Below is what I have got

BSF TRISC,CCP1 ;CCP1 (RC2) PIN AS INPUT
MOVLW B'10000001' ;Timer1 as clk for CCP1
MOVWF T3CON
MOVLW B'10000001' ;enable Timer1 in 16-bit mode, set prescaler to 1 use instruction clk cycle
MOVWF T1CON
MOVLW B'00000101' ;set CCP1 to capture mode, capture on every riseing edge
MOVWF CCP1CON

CALL PULSE ;Record timer reading when 1st pulse arrives
MOVFF CCPR1L,0X0 ;Save timer value in mem addresses 0X0 and 0X1 when 1st pulse arrives
MOVFF CCPR1H,0X1
CALL PULSE ;Record timer reading when second pulse arrives
CLRF CCP1CON ;Disbable more captures
MOVFF CCPR1L,0X2 ;Save timer value in mem addresses 0x2 and 0x3 when 2nd pulse arrives
MOVFF CCPR1H,0X3
CALL RESULT ;Compute periode measured in clock cycles
HERE BRA HERE

PULSE BCF PIR1,CCP1IF ;Clear timer int flag
CHECK BTFSS PIR1,CCP1IF ;rising edge arrived? (bit test, skip if set)
BRA CHECK ;if not loop back
RETURN

RESULT MOVF 0X0,W ;lst-pulse low byte reading to W
SUBWF 0X2,F ;subtract W from 2nd-pulse low byte reading, save in mem address 0x2
MOVF 0X1,W ;2nd-pulse high byte reading to W
SUBWFB 0x3,1 ;Subtract W from 2nd-pulse high byte reading, save in mem address 0x3

Now when I try and debug the code it came up with the following errors:

Debug build of project `C:\Documents and Settings\Family\My Documents\Alex\Flips.mcp' started.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Sun Feb 07 10:37:54 2010
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F877A "obj\f877atempo.asm" /l"f877atempo.lst" /e"f877atempo.err" /o"f877atempo.o" /d__DEBUG=1
Message[302] OBJ\F877ATEMPO.ASM 62 : Register in operand not in bank 0. Ensure that bank bits are correct.
Error[113] OBJ\F877ATEMPO.ASM 62 : Symbol not previously defined (CCP1)
Error[113] OBJ\F877ATEMPO.ASM 64 : Symbol not previously defined (T3CON)
Warning[207] OBJ\F877ATEMPO.ASM 71 : Found label after column 1. (MOVFF)
Error[122] OBJ\F877ATEMPO.ASM 71 : Illegal opcode (CCPR1L)
Warning[207] OBJ\F877ATEMPO.ASM 72 : Found label after column 1. (MOVFF)
Error[122] OBJ\F877ATEMPO.ASM 72 : Illegal opcode (CCPR1H)
Warning[207] OBJ\F877ATEMPO.ASM 75 : Found label after column 1. (MOVFF)
Error[122] OBJ\F877ATEMPO.ASM 75 : Illegal opcode (CCPR1L)
Warning[207] OBJ\F877ATEMPO.ASM 76 : Found label after column 1. (MOVFF)
Error[122] OBJ\F877ATEMPO.ASM 76 : Illegal opcode (CCPR1H)
Error[122] OBJ\F877ATEMPO.ASM 78 : Illegal opcode (BRA)
Warning[207] OBJ\F877ATEMPO.ASM 82 : Found label after column 1. (BRA)
Error[122] OBJ\F877ATEMPO.ASM 82 : Illegal opcode (CHECK)
Warning[207] OBJ\F877ATEMPO.ASM 88 : Found label after column 1. (SUBWFB)
Error[108] OBJ\F877ATEMPO.ASM 88 : Illegal character (0)
Error[129] OBJ\F877ATEMPO.ASM 96 : Expected (END)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Family\My Documents\Alex\Flips.mcp' failed.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Sun Feb 07 10:37:56 2010
----------------------------------------------------------------------
BUILD FAILED

So what’s wrong with the code is the question?
Also now that I have the time stored in clock pulses in mem address 0x2 and mem address 0x3 how do I send this to a look up table in order to correct my frequency and thus display the frequency in my LCD display?

Thanks for any help

Mark
 
Hi Mark,

Well as you are seeing its really a case of learning to walk first.

The code you have used is from the 18F series that has several different instructions that are not compatible with the 16F you are using.

For a beginner I would say its ok to use other folks complete code examples like Nigels LCD code as they are complicated routines, but that does not mean you can just pick and use loads of different examples and they will work together - they need to be integrated properly.

You really need to practice creating a whole simple starter program like the proverbial flashing led and build on things from there - thats the whole point of Nigels course.

hth
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top