PIC12C508 Read and Write 93LC46 Sample Program

/*************************************************** * Processor : Microchip PIC12C508 * Compiler : Hi-TECH PICC 8.00 PL2 * Author : Jason Kuo * Description : This code is designed to read and write data from the 93LC46 EEPROM (64 x 16-bit memory organization) ***************************************************/ static volatile unsigned char RTCC @ 0x01; static volatile unsigned char TMR0 @ 0x01; static volatile unsigned char PCL @ 0x02; static volatile unsigned char STATUS @ 0x03; static unsigned char FSR @ 0x04; static volatile unsigned char OSCCAL @ 0x05; static volatile unsigned char GPIO @ 0x06; static unsigned char control_OPTION @ 0x00; static volatile unsigned char control_TRIS @ 0x06; /* STATUS bits */ static bit GPWUF @ (unsigned)&STATUS*8+7; static bit PA0 @ (unsigned)&STATUS*8+5; static bit TO @ (unsigned)&STATUS*8+4; static bit PD @ (unsigned)&STATUS*8+3; static bit ZERO @ (unsigned)&STATUS*8+2; static bit DC @ (unsigned)&STATUS*8+1; static bit CARRY @ (unsigned)&STATUS*8+0; /* OPTION bits */ #define GPWU (1 << 7) #define GPPU (1 << 6) #define T0CS (1 << 5) #define T0SE (1 << 4) #define PSA (1 << 3) #define PS2 (1 << 2) #define PS1 (1 << 1) #define PS0 (1 << 0) /* OSCCAL bits */ static volatile bit CAL3 @ (unsigned)&OSCCAL*8+7; static volatile bit CAL2 @ (unsigned)&OSCCAL*8+6; static volatile bit CAL1 @ (unsigned)&OSCCAL*8+5; static volatile bit CAL0 @ (unsigned)&OSCCAL*8+4; /* GPIO pins */ static volatile bit GP5 @ (unsigned)&GPIO*8+5; static volatile bit GP4 @ (unsigned)&GPIO*8+4; static volatile bit GP3 @ (unsigned)&GPIO*8+3; static volatile bit GP2 @ (unsigned)&GPIO*8+2; static volatile bit GP1 @ (unsigned)&GPIO*8+1; static volatile bit GP0 @ (unsigned)&GPIO*8+0; #define CONFIG_ADDR 0xFFF /* Code protection settings */ #define MCLREN 0xFFFF // Enable memory clear #define MCLRDIS 0xFFEF // Disable memory clear #define WDTEN 0xFFFF // Enable watchdog timer #define WDTDIS 0xFFFB // Disable watchdog timer #define PROTECT 0xFFF7 // Protect program code #define UNPROTECT 0xFFFF // No protection /* Oscillator configurations */ #define EXTRC 0xFFFF // External RC oscillator #define INTRC 0xFFFE // Internal oscillator #define XT 0xFFFD // Crystal or resonator #define LP 0xFFFC // Low power crystal or resonator /* 93LC46 I/O pin definitions */ #define CS GP0 // Chip Select #define CLK GP1 // Serial Clock #define DI GP2 // Data Input #define DO GP4 // Data Output void Delay(unsigned int counter); void Pulse(void); void StartBit(void); void EWEN(void); void EWDS(void); extern void Write93LC46(unsigned char Offset_Addr, unsigned int tx_data); extern unsigned int Read93LC46(unsigned char Offset_Addr); void InitPIC(void); #define CLRWDT() asm("clrwdt") #define SLEEP() asm("sleep") #define ___mkstr1(x) #x #define ___mkstr(x) ___mkstr1(x) #define __CONFIG(x) asm("tpsect config,class=CONFIG,delta=2"); asm("tglobaltconfig_word"); asm("config_word"); asm("tdw " ___mkstr(x)); #define __IDLOC(w) asm("tpsect idloc,class=IDLOC,delta=2"); asm("tglobaltidloc_word"); asm("idloc_word"); asm("tirpct__arg," ___mkstr(w)); asm("tdw 0&__arg&h"); asm("tendm"); __CONFIG(MCLRDIS & WDTDIS & EXTRC & PROTECT); /*-------------------------------------------------- Function : Delay Input : unsigned int (counter) Output : None Description : A simple delay function based on internal clock. If counter = 1, delay ~35us If counter = 10, delay ~134us If counter = 100, delay ~1.12ms This timing is based on a 4MHz internal oscillator --------------------------------------------------*/ void Delay(unsigned int counter) { while(counter > 0) counter--; } /*-------------------------------------------------- Function : Pulse Input : None Output : None Description : Generate a 10 microsecond pulse on the CLK pin --------------------------------------------------*/ void Pulse(void) { CLK = 1; Delay(25); CLK = 0; }

Indoor Led Display

Indoor Led Display,Indoor digital signage,LED Display for Indoor Use,Digital signage LED Screen,Indoor Full HD LED Display,Indoor LED Display Panel

Shenzhen Xinfei Century Technology Co., Ltd. , https://www.rgbdancing.com