⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ram.c

📁 pic18f8680的内置can通信程序
💻 C
字号:
#include<p18f8680.h>
#include <usart.h>


void RAM_initial(void)
{
	EECON1 = 0x84;//使用flash空间,可写
	MEMCON = 0x00;//外部数据线使能
}

void RS232_initial(void)
{
	TRISC = 0X80;//c对应口input
	TXSTA = 0X04;//设定TXSTA寄存器。高速
    SPBRG = 64;//10MHZ, BRGH=1, 9600BPS.
    PIE1 = 0;//清除PIE1所有中断使能。
    RCSTA = 0X80;//禁止接收。
	INTCON = 0XC0;//清中断
}

void RS232_send(int RS232_date)
{
	TXREG = RS232_date;
	TXSTAbits.TXEN=1;//启动发送,TSR开始移位操作。
	while (PIR1bits.TXIF==0);//等待中断,在此为查询方式。
	while (TXSTAbits.TRMT==0);//判断是否TSR发送完毕,未完等待。
	TXSTAbits.TXEN=0;//关发送功能,防止TXREG空时,TXIF产生置位。
}

void main(void)
{
	char temp=0;
	RAM_initial();
	RS232_initial();
	TABLAT = 0x55;

	TBLPTRU=0x01;
	TBLPTRH=0x00;
	TBLPTRL=0x00;

	while(TBLPTRU<0x05)
	{
		_asm
			TBLWT
		_endasm

		TABLAT=0;

		_asm
			TBLRDPOSTINC
		_endasm

		RS232_send(TABLAT);

		temp = TABLAT;
		_asm
			TBLRDPOSTINC
		_endasm
		
		TABLAT = ++temp;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -