anderotegimendia
Newbie level 4
- Joined
- Feb 3, 2014
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 121
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include <htc.h> #include <pic.h> __CONFIG(MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & WDTE_OFF & PWRTE_ON & FOSC_INTRCIO); #define _XTAL_FREQ 400000 void main() { ANSEL = 0; // Set ports as digital I/O, not analog input ADCON0 = 0; // Shut off the A/D Converter CMCON = 7; // Shut off the Comparator VRCON = 0; // Shut off the Voltage Reference GPIO = 0; // Initializes GPIO with zero TRISIO= 0b001000; while(1) { GPIO= 0b010000; } }
#include <htc.h>
#include <pic.h>
#define _XTAL_FREQ 400000[COLOR="#FF0000"]0[/COLOR]
1-)How can I know if I have used an external Oscillator??? I configure it like this
__CONFIG(MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & WDTE_OFF & PWRTE_ON & FOSC_INTRCIO);
You think that 0 which is missing crystal frequency could be part of the problem why the microchip is not working?
---------------------------------------------------------------------------------------------
It's better to toggle pins into the loop, so that some activity can easily be measured...
And maybe with a bit of "visible" delay in between, say 50-100 mSecs
---------------------------------------------------------------------------------------------
#include <htc.h>
__CONFIG(MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & WDTE_OFF & PWRTE_ON & FOSC_INTRCIO);
#define _XTAL_FREQ 4000000
void main()
{
ANSEL = 0; // Set ports as digital I/O, not analog input
ADCON0 = 0; // Shut off the A/D Converter
CMCON = 7; // Shut off the Comparator
VRCON = 0; // Shut off the Voltage Reference
GPIO = 0; // Initializes GPIO with zero
TRISIO= 0b001000;
while(1)
{
__delay_ms(500);
GPIO ^= 0b010000;
}
}
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 ;****************************************************************************** ; This file is a basic code template for object module code * ; generation on the PIC12F675. This file contains the * ; basic code building blocks to build upon. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler and linker (Document DS33014). * ; * ; Refer to the respective PIC data sheet for additional * ; information on the instruction set. * ; * ;****************************************************************************** ; * ; Filename: xxx.asm * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;****************************************************************************** ; * ; Files required: P12F675.INC * ; * ; * ; * ;****************************************************************************** ; * ; Notes: * ; * ;****************************************************************************** ;------------------------------------------------------------------------------ ; PROCESSOR DECLARATION ;------------------------------------------------------------------------------ LIST P=12F675 ; list directive to define processor #INCLUDE <P12F675.INC> ; processor specific variable definitions ;------------------------------------------------------------------------------ ; ; CONFIGURATION WORD SETUP ; ; The 'CONFIG' directive is used to embed the configuration word within the ; .asm file. The lables following the directive are located in the respective ; .inc file. See the data sheet for additional information on configuration ; word settings. ; ;------------------------------------------------------------------------------ __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ;------------------------------------------------------------------------------ ; VARIABLE DEFINITIONS ;------------------------------------------------------------------------------ ; example of using Shared Uninitialized Data Section INT_VAR UDATA_SHR 0x20 W_TEMP RES 1 ; variable used for context saving STATUS_TEMP RES 1 ; variable used for context saving sGPIO RES 1 ;------------------------------------------------------------------------------ ; EEPROM INITIALIZATION ; ; The 12F675 has 128 bytes of non-volatile EEPROM, starting at address 0x2100 ; ;------------------------------------------------------------------------------ DATAEE CODE 0x2100 DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3 ;------------------------------------------------------------------------------ ; OSCILLATOR CALIBRATION VALUE ;------------------------------------------------------------------------------ OSC CODE 0x03FF ; Internal RC calibration value is placed at location 0x3FF by Microchip as ; a 0xADDLW K instruction, where the K is a literal value to be loaded into ; the OSCCAL register. ;------------------------------------------------------------------------------ ; RESET VECTOR ;------------------------------------------------------------------------------ RESET_VECTOR CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program ;------------------------------------------------------------------------------ ; INTERRUPT SERVICE ROUTINE ;------------------------------------------------------------------------------ INT_VECTOR CODE 0x0004 ; interrupt vector location MOVWF W_TEMP ; save off current W register contents MOVF STATUS,w ; move status register into W register MOVWF STATUS_TEMP ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere MOVF STATUS_TEMP,w ; retrieve copy of STATUS register MOVWF STATUS ; restore pre-isr STATUS register contents SWAPF W_TEMP,f SWAPF W_TEMP,w ; restore pre-isr W register contents RETFIE ; return from interrupt ;------------------------------------------------------------------------------ ; MAIN PROGRAM ;------------------------------------------------------------------------------ MAIN_PROG CODE START movlw b'001111' tris GPIO clrf GPIO LOOP btfsc GPIO,3 goto LOOP bsf GPIO,5 LOOP1 btfsc GPIO,3 goto LOOP1 movlw b'000000' movwf GPIO ;bsf GPIO,4 goto LOOP END ;------------------------------------------------------------------------------ ; OSCCAL RESTORE (not required if internal OSC is not used) ;------------------------------------------------------------------------------ errorlevel -302 BSF STATUS,RP0 ; set file register bank to 1 CALL 0x3FF ; retrieve factory calibration value MOVWF OSCCAL ; update register with factory cal value BCF STATUS,RP0 ; set file register bank to 0 errorlevel +302 ;------------------------------------------------------------------------------ ; PLACE USER PROGRAM HERE ;------------------------------------------------------------------------------ GOTO $ END ; directive 'end of program'
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?