I'm trying to get this idea to fly on a 16f1825
the code when converted to C works fine (I get a nice pwm waveform at 60.85 hz)
but it won't fly with pbp3 yet
Code:
/*
* File: newmain.c
* Author: richard
*
* Created on 23 August 2014, 7:25 PM
*/
#include <xc.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
typedef unsigned char byte;
#define bit_time 100 // 9600 ok @8mhz
#define serout_pin PORTAbits.RA0
#define _XTAL_FREQ 32000000
void send_serial( char data);
void ser_str(char *buff);
byte prnb[20];
uint16_t duty;
void main(void) {
OSCCON=0X70;
ANSELA=0;
ANSELC=0;
TRISA = 0b001110;
TRISC=0b11111001;
PORTA=255;
__delay_ms(2000);
T1CON = 0b00000000 ;
PIE1 = 0b00000001;
INTCON = 0b11000000;
CCP4CON = 0b00001001;
duty = 32768 ;
CCPR4H=duty>>8;
CCPR4L=duty;
T1CONbits.TMR1ON=1;
strcpy(prnb,"ready");
ser_str(prnb);
INTCON=0xc0;
while(1){
strcpy(prnb," loop ");
ser_str(prnb);
sprintf(prnb,"%4x",duty) ;
duty+=200;
ser_str(prnb);
CCPR4H=duty>>8;
CCPR4L=duty;
__delay_ms(2000);
}
return;
}
void interrupt ISR (void) {
CCP4CON=0;
CCP4CON=9;
PIR1bits.TMR1IF=0;
PORTCbits.RC2=!PORTCbits.RC2; // just to check interrupt
}
void send_serial( char data){ // bit_time 200us 4800 baud ,100 us 9600 ,400us 2400 (NOT INVERTED)
uint8_t i;
i=8; // 8 data bits to send
// di();
serout_pin = 0; // make start bit
__delay_us(bit_time);
while(i) // send 8 serial bits, LSB first
{
if(data&1) serout_pin = 1; // invert and send data bit
else serout_pin = 0;
data >>=1 ;//(data >> 1); // rotate right to get next bit
i--;
__delay_us(bit_time); // wait for baud
}
serout_pin = 1; // make stop bit
// ei();
__delay_us(bit_time);
}
void ser_str(char *buff){
char k = strlen(buff);
for (int j=0;j< k;j++){
send_serial(buff[j]);
}
}
Bookmarks