Continue to Site

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.

CMCON REGISTER IN PIC16F877

Status
Not open for further replies.

diamadiss

Member level 1
Member level 1
Joined
Mar 6, 2010
Messages
41
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,286
Activity points
1,654
Hello to everybody.I want to use two comporators from the PIC16F877 as "TWO INDEPENDENT COMPORATORS". In this part i have a problem with the register CMCON. This register lies in the bank 1. I state him as it seems below at page 1 with the IN\OUTS, but the MPLAB shows me an error. Can anybody help me to solve this problem? I want to underline you that this specific pic i haven't used him before. Thanks!:D

Code:
LIST P=16F877
INCLUDE "P16F877.INC"
DELAY1 		EQU 0X20
DELAY2 		EQU 0X21
DELAY3 		EQU 0X22
REG1 		EQU 0X34
ORG 0x00
BSF STATUS,RP0
MOVLW B'00000010' ;TWO INDEPENDENT COMPORATORS
MOVWF CMCON
MOVLW B'00111111' ;IN
MOVWF TRISB       ;IN
MOVLW B'11111111' ;OUT
MOVWF TRISC       ;OUT
BCF STATUS,RP0
START
........
 

Hi,

You are mixing up the 877 and 877A chips, the compare functions are quite different.

Try you code more like this -


Code:
	LIST P=16F877A
	INCLUDE "P16F877A.INC"

	
	CBLOCK 0X020
	DELAY1     
	DELAY2      
	DELAY3      
	REG1    
	ENDC  


		ORG 0x00
		GOTO	MAIN		; MUST BE USED TO JUMP OVER THE INTERRUPT VECTOR

MAIN	CLRF PORTA
		CLRF PORTB
		CLRF PORTC

		BSF STATUS,RP0
		
		; SET UP PORT A
		MOVWF	TRISA
	

		MOVLW B'00111111' ;IN
		MOVWF TRISB       ;IN

		MOVLW B'00000000' ;OUT
		MOVWF TRISC       ;OUT

		MOVLW B'00000010' ;TWO INDEPENDENT COMPORATORS
		MOVWF CMCON

		BCF STATUS,RP0

START
........

		END
 

    diamadiss

    Points: 2
    Helpful Answer Positive Rating
Can you explain me the red-painted commands that are listed below and what is their function because i don't know them. Thanks for your answers.






LIST P=16F877A
INCLUDE "P16F877A.INC"


CBLOCK 0X020
DELAY1
DELAY2
DELAY3
REG1
ENDC


ORG 0x00
GOTO MAIN ; MUST BE USED TO JUMP OVER THE INTERRUPT VECTOR

MAIN CLRF PORTA
CLRF PORTB
CLRF PORTC

BSF STATUS,RP0

; SET UP PORT A
MOVWF TRISA


MOVLW B'00111111' ;IN
MOVWF TRISB ;IN

MOVLW B'00000000' ;OUT
MOVWF TRISC ;OUT

MOVLW B'00000010' ;TWO INDEPENDENT COMPORATORS
MOVWF CMCON

BCF STATUS,RP0

START
........

END
 

Hi,

CBLOCK/ENDC are Directives, you can see all of them in the free download from Microchip - MPASM User Guide.
They have many uses in making your code easier to enter - in this case its far easier to just list them rather than use the EQU 0x21 etc, unless you need individual locations specifying.

The CLRF is a standard 16F instruction, it Clears to 0x00 the File, in this case PORTA, but you can use it anytime eg CLRF DELAY3.

Again you can see all the 16F instructions detailed in a section towards the end of the 877A datasheet.

Also open the 16F877A Template file which give you a ready made header code.
You can find it in Mplab - just open Microchip\MPASM Suite\ Template\Code\16f877ATemp.asm
 

What was the mistake in my code that forced the MPLAB to product an error. Would be there any posibility for my program work properly without commands :
CBLOCK
ENDC
CLRF
 

Hi,

If those commands were wrong Mplab would list them as an error.
If you get an error in the report, just point onto that line and click - it will take you straight to that line of code in your assembler.

Your original problem with CMCON was that the 877 chip you complied with does not have that Register - it is only used in the 877A chip - thats why my code above built without errors.

What errors are you getting now ??? - you need to show the code and errors in full.
 

In device P16F877A now works OK., but in device P16F877 doesn't work.Show i have to buy a P16F877A.

My code:

LIST P=16F877
INCLUDE "P16F877.INC"
DELAY1 EQU 0X20
DELAY2 EQU 0X21
DELAY3 EQU 0X22
REG1 EQU 0X34
ORG 0x00
BSF STATUS,RP0
MOVLW B'00000010' ;TWO INDEPENDENT COMPORATORS
MOVWF CMCON
MOVLW B'00111111' ;IN
MOVWF TRISB ;IN
MOVLW B'11111111' ;OUT
MOVWF TRISC ;OUT
BCF STATUS,RP0
START
MOVLW 00H
MOVWF REG1
LOOP
CALL DELAY
BTFSC PORTB,1
CALL TEMP
GOTO LOOP

TEMP
MOVLW 02H
MOVWF PORTC
RETURN


DELAY
MOVLW D'20'
MOVWF DELAY1
THIRD
MOVLW D'256'
MOVWF DELAY2
SECOND
MOVLW D'256'
MOVWF DELAY3
FIRST
DECFSZ DELAY3,1
GOTO FIRST
DECFSZ DELAY2,1
GOTO SECOND
DECFSZ DELAY1,1
GOTO THIRD
RETURN

END




BUILD:Deleting intermediary files... done.
Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F877A "Untitled.asm" /l"Untitled.lst" /e"Untitled.err"
Warning[205] C:\FFFFFF\UNTITLED.ASM 1 : Found directive in column 1. (LIST)
Warning[205] C:\FFFFFF\UNTITLED.ASM 2 : Found directive in column 1. (INCLUDE)
Message[301] C:\PROGRAM FILES\MPLAB IDE\MCHIP_TOOLS\P16F877.INC 37 : MESSAGE: (Processor-header file mismatch. Verify selected processor.)
Warning[205] C:\FFFFFF\UNTITLED.ASM 7 : Found directive in column 1. (ORG)
Warning[203] C:\FFFFFF\UNTITLED.ASM 8 : Found opcode in column 1. (BSF)
Warning[203] C:\FFFFFF\UNTITLED.ASM 9 : Found opcode in column 1. (MOVLW)
Warning[203] C:\FFFFFF\UNTITLED.ASM 10 : Found opcode in column 1. (MOVWF)
Error[113] C:\FFFFFF\UNTITLED.ASM 10 : Symbol not previously defined (CMCON)
Warning[203] C:\FFFFFF\UNTITLED.ASM 11 : Found opcode in column 1. (MOVLW)
Warning[203] C:\FFFFFF\UNTITLED.ASM 12 : Found opcode in column 1. (MOVWF)
Message[302] C:\FFFFFF\UNTITLED.ASM 12 : Register in operand not in bank 0. Ensure that bank bits are correct.
Warning[203] C:\FFFFFF\UNTITLED.ASM 13 : Found opcode in column 1. (MOVLW)
Warning[203] C:\FFFFFF\UNTITLED.ASM 14 : Found opcode in column 1. (MOVWF)
Message[302] C:\FFFFFF\UNTITLED.ASM 14 : Register in operand not in bank 0. Ensure that bank bits are correct.
Warning[203] C:\FFFFFF\UNTITLED.ASM 15 : Found opcode in column 1. (BCF)
Warning[203] C:\FFFFFF\UNTITLED.ASM 17 : Found opcode in column 1. (MOVLW)
Warning[203] C:\FFFFFF\UNTITLED.ASM 18 : Found opcode in column 1. (MOVWF)
Warning[203] C:\FFFFFF\UNTITLED.ASM 20 : Found opcode in column 1. (CALL)
Warning[203] C:\FFFFFF\UNTITLED.ASM 21 : Found opcode in column 1. (BTFSC)
Warning[203] C:\FFFFFF\UNTITLED.ASM 22 : Found opcode in column 1. (CALL)
Warning[203] C:\FFFFFF\UNTITLED.ASM 23 : Found opcode in column 1. (GOTO)
Warning[203] C:\FFFFFF\UNTITLED.ASM 26 : Found opcode in column 1. (MOVLW)
Warning[203] C:\FFFFFF\UNTITLED.ASM 27 : Found opcode in column 1. (MOVWF)
Warning[203] C:\FFFFFF\UNTITLED.ASM 28 : Found opcode in column 1. (RETURN)
Warning[207] C:\FFFFFF\UNTITLED.ASM 34 : Found label after column 1. (THIRD)
Warning[202] C:\FFFFFF\UNTITLED.ASM 35 : Argument out of range. Least significant bits used.
Warning[207] C:\FFFFFF\UNTITLED.ASM 37 : Found label after column 1. (SECOND)
Warning[202] C:\FFFFFF\UNTITLED.ASM 38 : Argument out of range. Least significant bits used.
Warning[207] C:\FFFFFF\UNTITLED.ASM 40 : Found label after column 1. (FIRST)
Warning[203] C:\FFFFFF\UNTITLED.ASM 47 : Found opcode in column 1. (RETURN)
Warning[205] C:\FFFFFF\UNTITLED.ASM 52 : Found directive in column 1. (END)
Halting build on first failure as requested.
BUILD FAILED: Sat Mar 06 23:29:19 2010
 

Hi,

Well most of the errors are because most lines of code should start after column 1 so just tab those lines as shown below.

The code builds without error but I have not ' run' to code to prove it does what you want.

Your delay values are invalid 0 - 255 is the max you can specify.

You specified the 877 chip but your project must be set to the 877A chip - you do not need to make a new project - just Configure, Select Device and then the right chip you actually want.

Remember the 877 does not have the CMCON registers, if you download the 877 datasheet and compare it to the 877A it is a very different set up - this is unusual when having two such chips 877 and 877A, generally the differences are very minor.
I would refine your code before buying a new chip, I have not used the Compare functions myself - you may find it can be done on the 877 if you have bought that chip, although the 877A should be cheap enough.


Have a look at this tutorial for more info on Compare.
**broken link removed**





Code:
	LIST P=16F877A
	INCLUDE "P16F877A.INC"
DELAY1 EQU 0X20
DELAY2 EQU 0X21
DELAY3 EQU 0X22
REG1 EQU 0X34
	ORG 0x00
	GOTO MAIN

MAIN BSF STATUS,RP0
	MOVLW B'00000010' ;TWO INDEPENDENT COMPORATORS
	MOVWF CMCON
	MOVLW B'00111111' ;IN
	MOVWF TRISB ;IN
	MOVLW B'11111111' ;OUT
	MOVWF TRISC ;OUT
	BCF STATUS,RP0
START
	MOVLW 00H
	MOVWF REG1
LOOP
	CALL DELAY
	BTFSC PORTB,1
	CALL TEMP
	GOTO LOOP
	
TEMP
	MOVLW 02H
	MOVWF PORTC
	RETURN
	
	
DELAY
	MOVLW D'20'
	MOVWF DELAY1
THIRD
	MOVLW D'255'
	MOVWF DELAY2
SECOND
	MOVLW D'255'
	MOVWF DELAY3
FIRST
	DECFSZ DELAY3,1
	GOTO FIRST
	DECFSZ DELAY2,1
	GOTO SECOND
	DECFSZ DELAY1,1
	GOTO THIRD
	RETURN
	
	END
 

    diamadiss

    Points: 2
    Helpful Answer Positive Rating
Wp100 thanks for helping me to understand some new things.:D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top