-
Search Results
-
I’m doing ADC with PIC 18F46K22, 16×2 lcd, LM3 temperature sensor, 20 MHz oscillator, MPLAB XC8 and PicKit3 programmer. I can do the generate the hex file and simulate it on Proteus and it works fine, but on hardware it doesn’t work. The LCD is switched on, but doesn’t display the analog value.
I wrote a small program to switch the led on off with delay and write something on the LCD on off with delay and this works on Proteus and hardware.
Please assist
Topic: MPLAB vs Hi-Tech C vs XC8
Hello guys,
I wish to learn about PIC programming via MPLAB. There are many compiler in MP lab such as Hi-Tech C, XC8 and so on. Can someone please explain the differences between each compilers and when to use them.
Thank you!
Dilshan
Topic: I2C PIC18F4550 to PIC18F4550
Hi,
I was checking your nice tutorial from here:
https://electrosome.com/i2c-pic-microcontroller-mplab-xc8/
<div class=”post-message ” dir=”auto” data-role=”message”>
<div>I decided to try it with PIC18F4550 to PIC18F4550 and I went in troubles.
I have tested your Proteus project with PIC16F877A and works fine.
Then I decided to replace PIC16F877A with PIC18F4550.
I have an error and maybe you can take a look and give some hints. The error comes from Slave code.
I made the changing from PIC16F877A to PIC18F4550 in 2 steps.
In the first step I have changed only the Master with PIC18F4550 and the Slave was still PIC16F877A.
Everything worked fine here. In my case the Master only reads from Salve and display the switches result on LEDs.
Here is the screenshots and XC8 code, the Master C code and “pro2.zip” with Proteus + MPLABX full XC8 code for Master and Slave:
https://goo.gl/uTijwg
This project works fine.In the second step I have changed also the Slave with PIC18F4550.
Here is the screenshots and XC8 code, the Master and the Slave C code and “pro3.zip” with Proteus + MPLABX full XC8 code for Master and Slave:
https://goo.gl/dnGDMQHere I have a problem and for sure comes from Slave XC8 code.
When I compile it says “variable “_z” is not used” and “portion of expression has no effect” where z is used.
Could you please help to debug the problem?</div>
</div>Greetings,
I have a few question to ask regarding my circuit in Proteus 8.6. I’ve constructed a circuit that posted in this link –> https://electrosome.com/switch-pic-microcontroller-hi-tech-c/ . I also built the program using the Hitech C compiler using Mplab software. And then, when I try to run the simulation in the Proteus using the hex file I built in Mplab, it didn’t even say error or something like that, instead, the led in the circuit itself won’t light up (no error message in Proteus while I run the simulation). I already tried to reinstall all my programming and other software (mplab, proteus, hitech c). But, it doesn’t work. What should I do? This is really stressing me out. This website is the only one where I can study more about Embedded Programming.
p/s: Pictures are included in this forum for reference.Thank you.
Topic: Problems with SPI
Hey guys,
I am working with PIC18F4620 micro in MPLAB with XC8 compiler below is the code I have written to initialize SPI. In the code i am trying to generate clock pluses by continuously sending 0xAA to the SPI output and I am simulating this code in PIC18 simulator, but I am not getting any signal on either of the pins (clk or the DO) and similarly I am also not getting any signal on the IC too. In simulation it is stuck at SSPSTAT –> BF waiting for it to go high and even if I set the flag high in simulation manually it still won’t generate any clock signal.
There must be some silly mistake that I might have made please have a look.Code
#include <xc.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <pic18f4620.h>
// PIC18F4620 Configuration Bit Settings
// CONFIG1H
#pragma config OSC = HSPLL // Oscillator Selection bits (HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1))
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRT = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON // Brown-out Reset Enable bits (Brown-out Reset enabled and controlled by software (SBOREN is enabled))
#pragma config BORV = 3 // Brown Out Reset Voltage bits (Minimum setting)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = OFF // Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-003FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (004000-007FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (008000-00BFFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (00C000-00FFFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (00C000-00FFFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
#define rs PORTDbits.RD6 //LATBbits.LB6
#define en PORTDbits.RD7 //LATBbits.LB7
#define _XTAL_FREQ 40000000
#define le PORTDbits.RD4 //bus bar control
#define watch 0b00000001
#define drain_valve 0b10000000
#define cal_led 0b01000000
#define level_sw PORTEbits.RE2
#define CS_PIN PORTCbits.RC2 //3 // Chip Select
#define TRIS_CS_PIN TRISCbits.TRISC2
#define DIN_PIN PORTCbits.RC4 // Data in
#define TRIS_DIN_PIN TRISCbits.TRISC4
#define DOUT_PIN PORTCbits.RC5 //6 // Data out
#define TRIS_DOUT_PIN TRISCbits.TRISC5
#define SCK_PIN PORTCbits.RC3 //5 // Clock
#define TRIS_SCK_PIN TRISCbits.TRISC3
void config_spi(void);
unsigned char write_spi(unsigned char mybyte);
unsigned char read_spi(void);
void main(){
TRISB =0x00; // lcd 0-7
TRISD =0x00; // D6, D7
TRISC = 0b10010011;
TRISE =0b101;
PORTEbits.RE1 = 0;
PORTB =0x00;
PORTD =0x00;
CS_PIN = 1; // Chip Select
ADCON0 = 0x00;
ADCON1 = 0b00001111; // all pins digital
unsigned char data=’a’;
config_spi();
while(1) write_spi(0xAA);
}
void config_spi(void){
TRIS_CS_PIN = 0;
TRIS_DIN_PIN = 1;
TRIS_DOUT_PIN = 0;
TRIS_SCK_PIN = 0;
SSPSTAT =0b10000000;
//SSPCON1 =0x22;
SSPCON1 = 0b00100010;
SSPADD =0x00;
CS_PIN = 0; // Chip Select
}
unsigned char write_spi(unsigned char mybyte){
SSPCON1bits.WCOL =0;
PIR1bits.SSPIF =0;
SSPBUF = mybyte;
//while(!SSPSTATbits.BF);
while(!PIR1bits.SSPIF);
return SSPBUF;
}
unsigned char read_spi(void){
while(!SSPSTATbits.BF);
return SSPBUF;
}
Hello,
I am working on PIC 12F1840 and MPLABX IDE 3.35 . I have written a code for reading PWM pulse width at one pin and writing that value to another PWM pin. But, at the time of simulation in logic analyzer output PWM pulse is not continuous. Is it a correct way to use capture mode and compare mode in one code ? Please check following code and guide me.
/* * File: general.c * Author: Murumkar * * Created on 25 January, 2017, 9:27 AM * * * read input (freq 400Hz) RA2 pulse width and write to RA5 (PWM with freq 18Kz) * * */ #include <stdio.h> #include <stdlib.h> #include <xc.h> #pragma config FOSC =INTOSC, PLLEN =OFF, WDTE =OFF, MCLRE =ON, #pragma config CLKOUTEN =OFF, IESO =OFF, FCMEN =OFF,CP =OFF, CPD =OFF,BOREN=OFF #pragma config WRT=OFF,STVREN=ON,BORV=LO,LVP=OFF unsigned char counter=0;//Overflow counter int count = 0; unsigned char timer1_value1 @ 0x2020; unsigned char timer1_value2 @ 0x2040; unsigned int timer1_value @ 0x2060; unsigned int Pulse @ 0x2080; unsigned int PulseWidth @ 0x20A0; delay() { int i; for(i=0;i<30;i++) { ; } } void pwm_start() { TRISAbits.TRISA2 = 1; APFCONbits.CCP1SEL = 0; CCP1CONbits.CCP1M = 0x05; // capture mode with each rising edge TRISAbits.TRISA2 = 0; TRISAbits.TRISA2 = 1; // RA2 as input ANSELAbits.ANSA2 = 0; // RA2 as Digital } void init_interrupt() { INTCONbits.GIE = 1; // enable global interrupt INTCONbits.PEIE = 1; // enable peripheral interrupt PIE1bits.TMR1IE = 1; // enable timer 1 PIE1bits.CCP1IE = 1; // enable capture mode interrupt } void pwm_again_start() { TRISAbits.TRISA5 = 1; // RA5 APFCONbits.CCP1SEL = 1; // CCP1 function on RA5 CCP1CONbits.CCP1M = 0x0C; // PWM mode: P1A active-high; P1B active-high CCP1CONbits.P1M = 0x00; // Single output; P1A modulated; P1B assigned as port pins PR2 = 0xDD; // CCPR1L = 0x00; // UPDATE PWM TON=0 CCP1CONbits.DC1B = 0x00; // the two LSbs of the PWM duty CYCLE PIR1bits.TMR2IF = 0; // TIMER2 FLAG CLEAR T2CONbits.T2CKPS = 0x00; // PRESCALER 1 T2CONbits.TMR2ON = 1; // TIMER 1 TRISAbits.TRISA5 = 0; // } void SetPWMDutyCyle(unsigned int duty_cycle_value) { CCP1CONbits.DC1B = duty_cycle_value & 0x03; // two LSbs of the PWM duty cycle. CCPR1L = (duty_cycle_value >> 2); // MSB VALUES while(PIR1bits.TMR2IF==1) { PIR1bits.TMR2IF =0; } T2CONbits.TMR2ON = 1; // TIMER 1*/ delay(); } void interrupt ISR() { if(PIE1bits.CCP1IE && PIR1bits.CCP1IF) { count++; if(count==1) { T1CONbits.TMR1ON = 1; // start timer 1 PORTAbits.RA1 = ~PORTAbits.RA1; counter = 0; PIR1bits.CCP1IF = 0; CCP1CONbits.CCP1M = 0x04; // capture mode with each falling edge timer1_value1 = TMR1L; timer1_value2 = TMR1H; timer1_value = timer1_value1 + (((int)TMR1H) << 8); } else if(count==2) { count = 0; PORTAbits.RA1 = ~PORTAbits.RA1; INTCONbits.GIE = 0; // disable global interrupt INTCONbits.PEIE = 0; // disable peripheral interrupt PIE1bits.TMR1IE = 0; // disable timer 1 PIE1bits.CCP1IE = 0; // disable capture mode interrupt counter = 0; PIR1bits.CCP1IF = 0; CCP1CONbits.CCP1M = 0x05; // capture mode with each rising edge timer1_value1 = TMR1L; timer1_value2 = TMR1H; Pulse = timer1_value1 + (((int)TMR1H) << 8); PulseWidth = Pulse - timer1_value; pwm_again_start(); SetPWMDutyCyle(PulseWidth); pwm_start(); init_interrupt(); } } } void micro_init() { OSCCONbits.SPLLEN = 0; // PLL DISABLE OSCCONbits.IRCF = 0x0F; // 16 MHZ INTERNAL FREQ OSCCONbits.SCS = 0x02; // INTERNAL OSCILLATR BLOCK } void main() { micro_init(); pwm_start(); TRISAbits.TRISA1 = 0; // RA1 as output ANSELAbits.ANSA1 = 0; // RA1 as digital TRISAbits.TRISA2 = 1; // RA2 as input ANSELAbits.ANSA2 = 0; // RA2 as Digital TRISAbits.TRISA5 = 0; // RA5 as output init_interrupt(); while (1) { ; } }thanking you ,
Gitanjali
Referring to the article : Integrating EM-18 RFID Module with PIC Microcontroller
I’m doing a project to make a prototype door lock when the RFID tag is detected by the EM-18.
I am using MPLAB X IDE v3.20 to program. Realizing that the code only supports MPLAB XC8, i tried to upload the hex file straight to my PIC18F4550 without building it on my IDE software.
However, the LCD is not displaying anything.
Is there anyway i can get my LCD to work with the code?
