找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5198|回复: 4
收起左侧

PIC16F690单片机初学者C语音编程参考

  [复制链接]
ID:395261 发表于 2018-9-8 10:12 | 显示全部楼层 |阅读模式
芯片采用PIC16F690,附件内容包括:
1.按键控制流水灯。
2.串口通讯。
3.定时器0计时4位数码管显示。
4.频率计。
5.PWM控制蜂鸣器。
6.外部中断。

MPLAB X IDE 无法正常编译执行中文路径下的PIC单片机程序。
如需要,请把程序的文件夹复制出来打开。
0.png

下面是其中一个单片机源程序如下:
  1. /*
  2. * File:   newmain.c
  3. * Author: YF006
  4. *
  5. * Created on 2018年7月11日, 上午8:20
  6. */

  7. #include "hardware.h"

  8.   // CONFIG
  9. #pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
  10. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
  11. #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
  12. #pragma config MCLRE = OFF      // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
  13. #pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
  14. #pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
  15. #pragma config BOREN = ON       // Brown-out Reset Selection bits (BOR enabled)
  16. #pragma config IESO = ON        // Internal External Switchover bit (Internal External Switchover mode is enabled)
  17. #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)

  18. unsigned int dutych=0;


  19. void interrupt Timer2_ISR(void)//这个不对
  20. {
  21.     if(TMR2IF)
  22.     {
  23.         //LED8=!LED8;
  24.         TMR2IF = 0;
  25.     }
  26. }

  27. int main() {

  28.     hardint();//系统初始化
  29.     ledint();//LED初始化
  30.     keyint();
  31.     pwmint();

  32.     while(1)
  33.     {
  34.         if(KEY==0)
  35.         {
  36.             delay_for(50);
  37.             if(KEY==0)
  38.             {
  39.                delay_for(10);
  40.                dutych++;  
  41.             }
  42.         }
  43.         if(dutych>5)
  44.         {
  45.             dutych=0;
  46.         }
  47.         
  48.         
  49.         if(dutych==0)
  50.         {
  51.             DC1B1=0;
  52.             DC1B0=0;
  53.             CCPR1L=0X00;
  54.             
  55.             LED1=0;
  56.             LED2=0;
  57.             LED3=0;
  58.             LED4=0;
  59.             LED5=0;
  60.         }        
  61.         if(dutych==1)
  62.         {
  63.             DC1B1=1;
  64.             DC1B0=1;
  65.             CCPR1L=0X0F;
  66.             
  67.             LED1=1;
  68.             LED2=0;
  69.             LED3=0;
  70.             LED4=0;
  71.             LED5=0;
  72.         }
  73.         if(dutych==2)
  74.         {
  75.             DC1B1=0;
  76.             DC1B0=1;
  77.             CCPR1L=0X1F;
  78.             
  79.             LED1=0;
  80.             LED2=1;
  81.             LED3=0;
  82.             LED4=0;
  83.             LED5=0;           
  84.         }
  85.         if(dutych==3)
  86.         {
  87.             DC1B1=1;
  88.             DC1B0=1;
  89.             CCPR1L=0X2E;
  90.             
  91.             LED1=0;
  92.             LED2=0;
  93.             LED3=1;
  94.             LED4=0;
  95.             LED5=0;            
  96.         }
  97.         if(dutych==4)
  98.         {
  99.             DC1B1=1;
  100.             DC1B0=0;
  101.             CCPR1L=0X3E;

  102.             LED1=0;
  103.             LED2=0;
  104.             LED3=0;
  105.             LED4=1;
  106.             LED5=0;           
  107.         }        
  108.         if(dutych==5)
  109.         {
  110.             DC1B1=0;
  111.             DC1B0=0;
  112.             CCPR1L=0X4E;
  113.             
  114.             LED1=0;
  115.             LED2=0;
  116.             LED3=0;
  117. ……………………

  118. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
PIC16F690 示例程序.zip (813.18 KB, 下载次数: 106)
回复

使用道具 举报

ID:468294 发表于 2020-1-4 06:39 | 显示全部楼层
学习了不少知识,谢谢楼主分享,顶一下!
回复

使用道具 举报

ID:333807 发表于 2020-2-13 11:24 | 显示全部楼层

学习了不少知识,谢谢楼主分享,顶一下!
回复

使用道具 举报

ID:690226 发表于 2020-2-18 16:05 | 显示全部楼层
学习了不少知识,谢谢楼主分享,顶一下!
回复

使用道具 举报

ID:1050521 发表于 2022-11-4 16:25 | 显示全部楼层
学习了不少知识,谢谢楼主分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表