CC5X -> XC8 PICプログラム書き換え(3)

いきなり完結編にいきます。
理由は、PICをオリジナルの12Fシリーズに合わせて
本当にただただXC8用の変更を入れたから。
コピペして、MLABでエラーが出たところだけ修正を加えました。

以下全文。

/*
* File: main_12f_MMPT.c
* Author: yamamotoeri
*
* Created on 2016/06/13, 21:01
*/

#include <stdio.h>
#include <stdlib.h>
#include <pic12f683.h>

/*
*
*/

#define BYTE char
#define TEXT unsigned char
#define COUNT int16
#define UCOUNT unsigned int
TEXT chg_wk;
TEXT bwk;
UCOUNT sec_cnt;
UCOUNT ad_wk;

/*add Sleep*/
#define Sleep() asm(” sleep”)
void interrupt int_server(void)
{
if(INTCON & 0x01){
INTCON &= ~0x09;
IOC &= ~0x08;
}
if(PIR1 & 0x01){
PIR1 &= ~0x01;
sec_cnt++;
}

return ;
}
int main(int argc, char** argv){

OSCCON = 0b01000000;
TRISIO = 0b00010100;
OPTION_REG = 0b10000111;
WPU = 0b00000000;
ANSEL = 0b01011100;
ADCON0 = 0b10001001;
CMCON0 = 0b00000111;
T1CON = 0b00100100;
TMR1H = 0b00000000;
TMR1L = 0b00000000;
INTCON = 0b01000000;
PIE1 = 0b00000001;
INTCON |= 0b10000000;
T1CON |= 0b00000001;
EEADR = 0b00000000;
EECON1 &= ~0b10000000;
EECON1 |= 0b00000001;

chg_wk = EEDAT;
GPIO |= 0b00000011;
sec_cnt = 0;
ad_wk = 0;
bwk = 0;

while(sec_cnt < 10){ ; }

while(1){

GPIO &= ~0b00000001;
GPIO &= ~0b00000010;

T_0:
ADCON0 = 0b10001101;
sec_cnt = 0;

if(ad_wk > 558){
bwk = 29;
}else{
bwk = 9;
}

while(sec_cnt < bwk){ ; }

ADCON0 |= 0b00000010;

while(1){
if(!(ADCON0 & 0b00000010)){
ad_wk = ADRESH;
ad_wk = ad_wk << 8;
ad_wk |= ADRESL;
ADCON0 = 0b10001001;
break ;
}
}

if(ad_wk < 900){
ad_wk = GPIO;
if(ad_wk & 0b00001000){
sec_cnt = 0;
while(sec_cnt < 1800){ ; }

goto T_0;
}

T1CON &= ~0b00000001;
PIE1 &= ~0b00000001;
INTCON &= ~0b01000000;
ad_wk = GPIO;
IOC = 0b00001000;
INTCON |= 0b00001000;

Sleep();

ANSEL |= 0b00001000;
T1CON |= 0b00000001;
PIE1 |= 0b00000001;
INTCON |= 0b01000000;
GPIO |= 0b00000010;

goto T_0;
}

ADCON0 |= 0b00000010;

while(1){
if(!(ADCON0 & 0b00000010)){
ad_wk = ADRESH;
ad_wk = ad_wk << 8;
ad_wk |= ADRESL;
break;
}
}

if(!(chg_wk & 0b00000001)){
if( ad_wk < 409 ){
EEADR = 0b00000000;
EEDAT = 0b00000001;
EECON1 &= ~0b10000000 ;
EECON1 |= 0b00000100;
EECON2 = 0b01010101;
EECON2 = 0b10101010;
EECON1 |= 0b00000010;
chg_wk |= 0b00000001;
}
}else{
if( ad_wk > 568 ){
EEADR = 0b00000000;
EEDAT = 0b00000000;
EECON1 &= ~0b10000000;
EECON1 |= 0b00000100;
EECON2 = 0b01010101;
EECON1 |= 0b00000010;
chg_wk &= ~0b00000001;
}
}

if(chg_wk & 0b00000001){
sec_cnt = 0;
GPIO |= 0b00000001;
GPIO |= 0b00000010;
while(1){
if(sec_cnt > 39){
break ;
}
}
}
}
}

 

以上!コンパイルもerror、morning共になしで通るはず。

コメントを残す

メールアドレスが公開されることはありません。